Друзья, после недели борьбы с NestedSetBehavior совсем отчаялся…
Суть проблемы — как с его помощью перенести одну ветку со всем вложенным множеством от одного родителя к другому.
В мануале упоминается код:
$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/>
Но по факту он выдает непонятную для меня ошибку
2011/10/26 19:27:15 [error] [exception.CDbException] exception 'CDbException' with message 'The node cannot be inserted because it is not new.' in /home/prj/www/protected/extensions/trees/NestedSetBehavior.php:601
Stack trace:
#0 /home/prj/www/protected/extensions/trees/NestedSetBehavior.php(324): NestedSetBehavior->addNode(Object(Category), '2', 1, true, NULL)
#1 /home/prj/yii/framework/base/CComponent.php(264): NestedSetBehavior->appendTo(Object(Category), true, NULL)
#2 /home/prj/yii/framework/db/ar/CActiveRecord.php(214): CComponent->__call(Array, Array)
#3 [internal function]: CActiveRecord->__call('appendTo', Array)
#4 /home/prj/www/protected/extensions/trees/NestedSetBehavior.php(336): Category->appendTo('appendTo', Array)
#5 /home/prj/yii/framework/base/CComponent.php(264): NestedSetBehavior->append(Object(Category), true, NULL)
#6 /home/prj/yii/framework/db/ar/CActiveRecord.php(214): CComponent->__call(Object(Category))
#7 [internal function]: CActiveRecord->__call(Array, Array)
#8 /home/prj/www/protected/modules/admin/controllers/CategoryController.php(91): Category->append('append', Array)
#9 [internal function]: CategoryController->actionUpdate('append', Array)
#10 /home/prj/yii/framework/web/actions/CAction.php(104): ReflectionMethod->invokeArgs(Object(Category))
#11 /home/prj/yii/framework/web/actions/CInlineAction.php(48): CAction->runWithParamsInternal('16')
#12 /home/prj/yii/framework/web/CController.php(300): CInlineAction->runWithParams(Object(CategoryController), Array)
#13 /home/prj/yii/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CategoryController), Object(ReflectionMethod), Array)
#14 /home/prj/yii/framework/web/filters/CFilter.php(41): CFilterChain->run(Array)
#15 /home/prj/www/protected/components/Controller.php(43): CFilter->filter(Object(CInlineAction))
#16 /home/prj/yii/framework/web/filters/CInlineFilter.php(59): Controller->filterUserGroupsAccessControl()
#17 /home/prj/yii/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))
#18 /home/prj/yii/framework/web/CController.php(283): CFilterChain->run(Object(CFilterChain))
#19 /home/prj/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CFilterChain))
#20 /home/prj/yii/framework/web/CWebApplication.php(277): CController->run()
#21 /home/prj/yii/framework/web/CWebApplication.php(136): CWebApplication->runController(Object(CInlineAction), Array)
#22 /home/prj/yii/framework/base/CApplication.php(158): CWebApplication->processRequest('update')
#23 /home/prj/www/index.php(30): CApplication->run('admin/category/...')
#24 {main} REQUEST_URI=/admin/category/update/id/16
Кто боролся и разобрался?