Allow nil values in array #1657
Open
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’ve noticed some inconsistent behavior when using the _in predicate in Ransack compared to ActiveRecord.
For example, in plain Rails:
We use Ransack in our API. Since Rails automatically strips any nil values from an array in params, it's not possible for us to use the standard
_inpredicate in our API. To accomplish this I've introduced a custom predicate_in_or_nullas described here: #940 (comment)This allows me to perform the second example by using
brand_in_or_null: [ "AUDI" ], however if I would usebrand_in_or_null: [], I would expect this to only give me the vehicles where the brand is null, however the current logic deletes the param and returns all records.I've changed the logic in the Search class initializer, where it now allows an array with nil values.
Possibly related to: #524