Skip to content

Running insertAfterNode when no data needs to change cause indexes to be null #147

@oddvalue

Description

@oddvalue

Say you had a table like this:

    id    _lft    _rgt  parent_id
------  ------  ------  ---------
     1       1       2     (NULL)
     2       3       4     (NULL)

Calling Node::find(2)->insertAfterNode(Node::find(1)); would cause the code to attempt to save row 2's _lft and _rgt as null.

This appears to be caused by the dirtyBounds method that nullifies _lft and _rgt and then during the save the queued move method asserts that the node doesn't need to move and continues through the save where nothing has reset the _lft or _rgt from null so it persists that to the DB.

What is the purpose of the dirtyBounds method? If I comment out the call to it in beforeOrAfterNode then this issue doesn't happen.

If it's in order to get eloquent to always think that they've changed could you achieve the same thing by nulling the _lft and _rgt in the $original array rather than $attributes?

Arguably you shouldn't be trying to tell a node to move to where it already is but this does feel like unexpected behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions