Let .roots select roots from any collection.#75
Open
dceluis wants to merge 1 commit intoamerine:masterfrom
Open
Let .roots select roots from any collection.#75dceluis wants to merge 1 commit intoamerine:masterfrom
dceluis wants to merge 1 commit intoamerine:masterfrom
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.activewhich could possiblyexclude some top-level roots, they're effectively nonexistent. Then,
doing
Record.active.rootsnow returns the relative roots, counting asroot 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
rootsreturn the same if called on the Class. Please share somefeedback/ thoughts.
Cheers.