acts_as_tree icon indicating copy to clipboard operation
acts_as_tree copied to clipboard

Let .roots select roots from any collection.

Open dceluis opened this issue 7 years ago • 1 comments

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.

dceluis avatar Feb 18 '18 12:02 dceluis

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.

felixbuenemann avatar Feb 20 '18 00:02 felixbuenemann