Closed karlingen closed 11 years ago
@karlingen You have error in your gist. Do not need do:
$fii->saveNode();
after you append it.
@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);
@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;
See this gist: https://gist.github.com/karlingen/35aec89ec2c0a475e9b4
It returns the same node even-though the node has a parent.