-
Notifications
You must be signed in to change notification settings - Fork 475
Description
Thank you very much for the effort you are putting to solve the issues.
Here i have a new one.
I have this simple data:
id | name | _lft | _rgt | parent_id |
---|---|---|---|---|
1 | NODE1 | 1 | 4 | NULL |
2 | NODE2 | 2 | 3 | 1 |
Then i append node 2 to itself
$node = Node::find(2);
$node2 = Node::find(2);
$node->appendTo($node2);
This is letting it happen, now the data looks like:
id | name | _lft | _rgt | parent_id |
---|---|---|---|---|
1 | NODE1 | 1 | 4 | NULL |
2 | NODE2 | 2 | 3 | 2 |
I made another test to debug the QueryBuilder moveNode
method:
/**
* Move a node to the new position.
*
* @param int $key
* @param int $position
*
* @return int
*
* @throws \LogicException
*/
public function moveNode($key, $position)
{
list($lft, $rgt) = $this->model->newServiceQuery()->getPlainNodeData($key, true);
dd($lft, $position, $rgt); // To know what data is coming to the condition!
if ($lft < $position && $position < $rgt)
{
throw new LogicException('Cannot move node into itself.');
}
I reverted the data as the initial shape at the beginning and did the append to itself again, this is what i get from those 3 variables:
$lft = 2
$position = 3
$rgt = 3
With this data the condition is not met and the exception is not thrown.
I understand that position
is set to the next of the node you are appending to, but as it is the same node it does not know that.
I think that a another condition can be done, something like:
if the node i want to append to is the same, then throw the exception.
What do you think?
Thanks