acts_as_tree
acts_as_tree copied to clipboard
Let .roots select roots from any collection.
I just realized that the .roots method only allows to get the roots from the top level. Meaning that only nodes with their foreign_key set to nil are considered roots.
But I think there would be nice if you could get the 'relative' roots.
For example, if we had a system that allowed to 'archive' some records,
we'd probably scope them as Record.active which could possibly
exclude some top-level roots, they're effectively nonexistent. Then,
doing Record.active.roots now returns the relative roots, counting as
root all those Records whose parent_id points to a record outside the
current scope (including nil parent_ids)
Same for filtered by date, last n number of records.. etc. The top
level roots return the same if called on the Class. Please share some
feedback/ thoughts.
Cheers.
I suggest you implement this as a custom scope in your app. Changing the behavior of the roots scope would certainly break code for existing users.