Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving a node causes it to attempt to also move the node to itself. #296

jcwatson11 opened this issue Jan 11, 2018 · 3 comments


None yet
3 participants
Copy link

commented Jan 11, 2018

I'm not sure what I'm doing wrong. But if I try to update a Baum node using Laravel/Eloquent and just use the save() method, it fires the Eloquent 'saved' event, which causes Baum to call moveToNewParent. But since I'm updating a node that doesn't actually need to be moved, it errors out with:

A node cannot be moved to a descendant of itself (inside moved tree).

My solution to this problem is to modify the moveToNewParent() method like so:

public function moveToNewParent() {
    $pid = static::$moveToNewParentId;

    if ( is_null($pid) )
    else if ( $pid !== FALSE ) {
      $pkey = $this->getKey();
      $childNode = static::find($pkey);
      $parentNode = static::find($pid);
      if($childNode && $parentNode && !$childNode->insideSubtree($parentNode)) {

Something doesn't feel right about this solution though, since I can't be the first to try to update a node without trying to move it.

What am I doing wrong?


This comment has been minimized.

Copy link

commented Feb 1, 2018

It looks like this package is not longer maintained by etrepat. We decided to fork the package and make the change for ourselves.


This comment has been minimized.

Copy link

commented Apr 4, 2018

Same problem, @jcwatson11 your code solution works for me.


This comment has been minimized.

Copy link

commented May 10, 2019

Guys checkout v2 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.