Descendants ordered #13

Closed
brendon opened this Issue Feb 12, 2010 · 2 comments

Projects

None yet

2 participants

@brendon
brendon commented Feb 12, 2010

Hi, sorry to bug you again, but I've run into a bit of a mindblank. With a nested set approach you can call self_and_decendants or descendants and get a result set that is ordered by the left column, thus ordered the way the user wants it. Is it possible to order by 'ancestry, position' and have a similar effect?

I'm trying to display the tree to the user :)

Cheers,

Brendon

Owner

Sure.

Have a look at the ordered_ancestry scope in the code and add a similar scope to your code, adding the position column.

Stefan

brendon commented Feb 14, 2010

Thanks Stefan, eventually I found that adding a default_scope to my model worked a treat. I also finally realised that 'subtree' is your name for 'self_and_descendants' lol so that all worked out. Subtree also seems to use the model's default ordering. I just ordered on 'ancestry is not null, ancestry, position'.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment