yiiext / nested-set-behavior

AR models behavior that allows to work with nested sets tree.
http://www.yiiframework.com/extension/nestedsetbehavior/
BSD 3-Clause "New" or "Revised" License
157 stars 64 forks source link

BUG: $node does not have function getIsDeletedRecord() when calling appendTo #32

Open ptheofan opened 10 years ago

ptheofan commented 10 years ago

This was hidden behind a rollback failure! Reached this after I modified if(isset($transaction) && $transaction->active) (at line 662)

Exception Message: Category and its behaviors do not have a method or closure named "getIsDeletedRecord". Trace:

0 /yii/db/ar/CActiveRecord.php(225): CComponent->__call('getIsDeletedRec...', Array)

1 /application/components/behaviors/NestedSetBehavior.php(904): CActiveRecord->__call('getIsDeletedRec...', Array)

2 /application/components/behaviors/NestedSetBehavior.php(904): Category->getIsDeletedRecord()

3 /application/components/behaviors/NestedSetBehavior.php(658): NestedSetBehavior->correctCachedOnAddNode('2')

4 /application/components/behaviors/NestedSetBehavior.php(325): NestedSetBehavior->addNode(Object(Category), '2', 1, true, NULL)

5 [internal function]: NestedSetBehavior->appendTo(Object(Category))

any quickfix ideas/solutions?

bupy7 commented 10 years ago

You likely attaching behavior in a controller for model like as $model->attachBehavior( 'nestedSetBehavior', array( 'class' => 'application.behaviors.NestedSetBehavior', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'levelAttribute' => 'level', 'hasManyRoots' => true, ) ); If added new record in root, then it does not caused problem. But! If added new record in existing record, then will be caused problem, which you described.

This is due to the fact what after getting model in which you want insert new record, you not attach behavior for this model! If this not do, you get exception, because in behavior exist property for validate and checking. In this case this property private $_deleted=false; at line 23.