Answer the question
In order to leave comments, you need to log in
Yii and NestedSetBehavior - moving branches?
Friends, after a week of fighting with NestedSetBehavior, I completely despaired ...
The essence of the problem is how to use it to transfer one branch with the entire nested set from one parent to another.
The manual mentions the code:
$model = $this->loadModel($id);<br/>
$model->deleteNode();<br/>
$model->refresh();<br/>
$parent = $this->loadModel(intval($_POST['Category']['parentId']));<br/>
$parent->append($model);<br/>
$model->refresh();<br/>
Answer the question
In order to leave comments, you need to log in
The whole point is that you are using the append method on a non-new (saved) model.
To move a saved model, you must use the move* methods, such as moveAfter, moveAsFirst, and so on.
Example. To change the parent, you can do this:
$model->moveAsFirst($parent); // вместо $parent->append($model);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question