Can i use positioned siblings list in ancestry? #7

xnutsive opened this Issue Oct 28, 2009 · 7 comments


None yet
3 participants


Can i use numbered list of siblings with ancestry?
Integer position field is a simple solution, but i can't get what do i use as a scope option for the list.

Could you, please, give me a clue?


stefankroes commented Oct 28, 2009

Please be more specific about which gem you are trying to use with Ancestry. My first guess would be that the ancestry column (usually just 'ancestry') could act as a scope. Records with the same ancestry are each other's siblings (makes sense when you think about it).

axtro commented Oct 28, 2009

What do you think of adding an "order" option to ancestry, so that every call which returns a list of tree nodes returns them according to the "order"-scope?
This would be the same as with the old acts_as_tree plugin, where you can give it a :order => <column_name> option.

Yep, something like that, as in acts_as_ordered_tree plugin, or in acts_as_tree + acts_as_list :scope => :parent_id.

Both solutions will go, either adding acts_as_list with :scope => :ancestry, or integrating that functionality in ancestry as an option.

Sadly, i don't have enough time to do that integration and publish it as a patch.


stefankroes commented Oct 28, 2009

I think acts_as_list and acts_as_tree should be two seperate concerns. I don't see any reason why acts_as_list shouldn't work in combination with ancestry (optionally with a scope on the ancestry column). Additionally you can pass an order option into any of the ancestry navigation methods that return a scope, like the documentation suggests. Also you can combine ancestry with a default_scope to apply default ordering. Please let me know if this answers your question.

axtro commented Oct 28, 2009

I was thinking about default_scope, too. Unfortunately we are still on 2.2, so that will not work. I guess passing in manually an :order option is good enough for us until we upgrade from 2.2.
Thanks for this plugin, btw :) The code is very concise and nice to read! I looked at the other materialized tree plugins available some time ago, but none convinced me to actually use it in an app. Details like the super easy conversion from parent_id based plugins are also very nice to have.

Stephan, you are right, they really are separate and it's just okay.

:order option will not do the trick — you'll have a list only on reading records, but you can't rearrage them in any order you want.

So, the solution is to use acts_as_list :scope => :ancestry. I'll try that.


stefankroes commented Oct 29, 2009

I'm closing this ticket for now.

This issue was closed.

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