You Should Not Use Cactiverecord::save() Method When Nestedsetbehavior Attached.

Hi, I am using NestedSetBehavior (http://www.yiiframework.com/extension/nestedsetbehavior/) in my Model.

Plus, I am also using Giix to generate Model and Crud.

In this case, when I click the button save in the webpage xxx/create, I got the following error:

"You should not use CActiveRecord::save() method when NestedSetBehavior attached."

After reading the document for NestedSetBehavior (http://www.yiiframework.com/extension/nestedsetbehavior/) , I found if I want to create a new model, I should use saveNode() instead of save(). However, the problem is, I used Giix to generate the Crud, so in the actionCreate function of XXController is:




if ($model->saveWithRelated($relatedData)) {

	if (Yii::app()->getRequest()->getIsAjaxRequest())

		Yii::app()->end();

	else

		$this->redirect(array('view', 'id' => $model->id));

}



which means it uses saveWithRelated() rather than save(). So I cannot use saveNode() to rewrite the function either.

So, please what should I do to save the model???

I hope this description is clear. If not, please tell me, I will try again.

Hi aslan,

I have never used NestedSetBehavior, but it seems that if all of the model’s relations are nodes, it should work using saveNode().

You’ll have to setup the transaction manually if you want to use it.

Bro, I found error like this "Undefined variable: relatedData ". Thanks.

edited.

Im so stupid, i use saveNode() which Rodrigo Coelho success