Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let .roots select roots from any collection. #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dceluis
Copy link

@dceluis dceluis commented Feb 18, 2018

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 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.
@felixbuenemann
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants