Let .roots select roots from any collection. #75
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.active
which could possiblyexclude some top-level roots, they're effectively nonexistent. Then,
doing
Record.active.roots
now 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
roots
return the same if called on the Class. Please share somefeedback/ thoughts.
Cheers.