This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

johnytributante17670
johnytributante17670

I followed the example from here: https://octobercms.com/docs/backend/reorder

And this is my table where i have menu categories with subcategories:

enter image description here

And it works fine. My records are sortable but when I tried to update some record which is main record(parent_id is null) then I have this error:

"Cannot resolve target node." on line 927...

This is from:

    protected function validateMove($node, $target, $position)
        {
            if (!$node->exists)
                throw new Exception('A new node cannot be moved.');

            if (!in_array($position, ['child', 'left', 'right'])) {
                throw new Exception(sprintf(
                    'Position should be either child, left, right. Supplied position is "%s".', $position
                ));
            }
            if ($target === null) {
                if ($position == 'left' || $position == 'right') {
                    throw new Exception(sprintf(
                        'Cannot resolve target node. This node cannot move any further to the %s.', $position
                    ));
                }
                else {
                    throw new Exception('Cannot resolve target node.');
//there i have this error when i tried to update record with parent_id = null
                }
            }

            if ($node == $target) {
                throw new Exception('A node cannot be moved to itself.');
            }

            if ($target->isInsideSubtree($node)) {
                throw new Exception('A node cannot be moved to a descendant of itself.');
            }

            return !(
                $this->getPrimaryBoundary($node, $target, $position) == $node->getRight() ||
                $this->getPrimaryBoundary($node, $target, $position) == $node->getLeft()
            );
        }

When I create new menu element or update element which have parent_id I havent problem only when I tried to update. Maybe someone can see where can i make mistake.

Octo
Octo

I had the same issue just now. My problem was that i have created dropdown and made it fetch items by parent_id and name (categories in my case). And got this error because NestedTree tried to assign that parent_id (which was 0 in many cases). So that is why NestedTree got confused when you save this item to itself. I Hope i am clear enough.

The solution is simple. In fields - make parent item as a relation:

parent:
    label: Parent
    type: relation
    nameFrom: name
    emptyOption: None

And that solved my problem. I hope this guides everyone else the right way too.

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.