creocoder / yii2-nested-sets

The nested sets behavior for the Yii framework.
Other
446 stars 129 forks source link

add support for deleting a root node #71

Closed schmunk42 closed 9 years ago

schmunk42 commented 9 years ago

I got this error with 0.9.0

Method "dmstr\modules\pages\models\Tree::delete" is not supported for deleting root node.
Stack trace:
#0 [internal function]: creocoder\nestedsets\NestedSetsBehavior->beforeDelete(Object(yii\base\ModelEvent))
#1 /app/vendor/yiisoft/yii2/base/Component.php(538): call_user_func(Array, Object(yii\base\ModelEvent))
....

Is there a special reason why this is denied?

creocoder commented 9 years ago

@schmunk42 Use deleteWithChildren for it. Method delete remove only one node and move its children to same level. Its not possible for root nodes. While deleteWithChildren remove node and its children complettely. You can find same different removing strategy in other NS implementations.

schmunk42 commented 9 years ago

Thanks, I didn't recognize that.

cornernote commented 9 years ago

Would be awesome if this was in the readme. I had the same issue.