Support IN queries on array columns #51137
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.
Motivation / Background
A non-array column can be queried via
where(name: [value1, value2])
which is automatically converted toname IN (value1, value2)
in SQL. An array column would treat that array as the value to search for, so it'd be natural to expect an array of arrays would result in anIN
query. Unfortunately, that wasn't the case aswhere(name: [[value1], [value2]])
would returnname = {{value1}, {value2}}
in SQL, instead ofname IN ({value1}, {value2})
.Detail
That behavior stemmed from the fact that Active Record would force equality comparison for array columns if the value was an array. In order to allow
IN
queries this check was change to check whether it's a one-dimensional array by checking that the first item of is not an array.After these changes the following logic applies for querying array columns:
IN
query.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]