Saving a node causes it to attempt to also move the node to itself.
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) )
$this->makeRoot();
else if ( $pid !== FALSE ) {
$pkey = $this->getKey();
$childNode = static::find($pkey);
$parentNode = static::find($pid);
if($childNode && $parentNode && !$childNode->insideSubtree($parentNode)) {
$this->makeChildOf($pid);
}
}
}
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?
It looks like this package is not longer maintained by etrepat. We decided to fork the package and make the change for ourselves.
Same problem, @jcwatson11 your code solution works for me.
Guys checkout v2 :)