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

Loading 'descendants' gives back faulty data #14

Closed boazrymland closed 11 years ago

boazrymland commented 11 years ago

Hi,

I'm developing a comments module for Yii (to be released when its finished). I needed some test data in the tables in order to develop it. I'm using the following test data to simulate. The tree diagram and the test data are all described nicely in this document (I hope that you can see the diagram in it too - let me know otherwise).

In my code, I fetch all comments for 'article' with id=51 and indeed I get the correct results - array of 'comment' models, of ids=5,4,1.

Now, when I loop (foreach=) over them, starting with commend 5, I do: $descendants = $root->descendants()->published()->findAll() and the results I get is not what I expect. I get an array containing the following comments: 2 and 6. I expected to get only 1 descendant - comment with id=6, with its level=1 (probably). Both of the comments (2 and 6) also has level=0 but maybe that has to do with the manual insertion of comment I did to the DB ?

Could the reason be also related to the manual insertion of comments to the DB?

Thanks! Boaz.

boazrymland commented 11 years ago

Ok, problem found. Thing is that I didn't set 'hasManyRoots' to true as needed. I think that several extra words on that (and on 'level' and 'root' columns) in the documentation are in place. I'll add those and issue a PR for your convenience.

creocoder commented 11 years ago

Yes PR will be good.