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

parent() not returning parent #27

Closed karlingen closed 11 years ago

karlingen commented 11 years ago

See this gist: https://gist.github.com/karlingen/35aec89ec2c0a475e9b4

It returns the same node even-though the node has a parent.

creocoder commented 11 years ago

@karlingen You have error in your gist. Do not need do:

$fii->saveNode();

after you append it.

karlingen commented 11 years ago

@creocoder That is not entierly true. I've tried with values that are already there in the Database. When saving the nodes and then doing this:

$category = Category::model()->findByPk(2); echo $category->parent()->id;

..it still returns the child's ID and not the parent ID.

Here is the content in the database: INSERT INTO tbl_category (id, content, root, lft, rgt, level) VALUES (1, 'parent', 1, 1, 4, 1), (2, 'child', 1, 2, 3, 2);

creocoder commented 11 years ago

@karlingen You mistake is u use it this way:

$category->parent()->id;

Method parent() is scope and this should be used that way:

$category->parent()->find()->id;