-
Notifications
You must be signed in to change notification settings - Fork 26
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
New Lookup
PORO
#2679
Merged
Merged
New Lookup
PORO
#2679
Conversation
This file contains 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
This is intended to be an "omnivorous" looker-upper, that can handle a single string, ID, or instance, or a mixed array of those. It has methods to return ids or instances, or in the case of names, subtaxa/synonymy subsets for testing.
Simplify prepare_vals
Try to tame code
Fix inheritance, assertions
just remove former Lookup Names test
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.
Lookup
is a new class of POROs to flexibly parse index filtering params. This was previously handled by instance methods insideQuery::Modules::LookupObjects
andLookupNames
. Moving this to a PORO makes these lookups available to model scopes and tests, independently testable, and hopefully easier to debug.These lookups are used in searches like "Observations by (given) Users" "Observations for (given) Projects". We can filter more than one project at a time, for example "NEMF 2023" and "NEMF 2024". Query needs the IDs, though (as would ActiveRecord), so the lookup handler makes the param format flexible for the caller. With projects, we can pass strings or ids, and Query will make sense of them.
projects: ["NEMF 2024", 234]
. With a users filter, the choices are instances or ids:users: [users(:mary), 4567432]
.The new class
Lookup
is intended as a more "omnivorous" looker-upper of records. It can handle any identifiers we're likely to throw at it: a string, ID, instance, or a mixed array of any of those. Thelookup_method
has to be configured in the Lookup child class, because the lookup column names are different for each model.A
Lookup
instance has accessor methods that return either an array ofids
,instances
ortitles
of the records matched.Query
already hasLookupObjects
andLookupNames
modules that do something very much like this, but they don't handle as many cases:Query
param configurations handle either names+ids or instances+ids. After this PR, it will be possible to adjust Query to handle all three in all cases, allowing us to consolidate duplicative params likeproject
/projects
that make the class more confusing.