Skip to content
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

Support IN queries on array columns #51137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Support `IN` queries of array columns.

Use `where(tags: [["tag1"], ["tag2"]])` to produce an `tags IN ({'tag1'}, {'tag2'})`,
similarly to how it works with non-array columns.

*Greg Navis*

* Add ActiveRecord::Encryption::MessagePackMessageSerializer

Serialize data to the MessagePack format, for efficient storage in binary columns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def changed_in_place?(raw_old_value, new_value)
end

def force_equality?(value)
value.is_a?(::Array)
value.is_a?(::Array) && !value.first.is_a?(::Array)
end

private
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/adapters/postgresql/array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ def test_where_by_attribute_with_array
assert_equal record, PgArray.where(tags: tags).take
end

def test_where_by_attribute_with_array_of_arrays
PgArray.create!(tags: ["black"])
PgArray.create!(tags: ["blue"])
assert_equal 2, PgArray.where(tags: [["black"], ["blue"]]).count
end

def test_uniqueness_validation
klass = Class.new(PgArray) do
validates_uniqueness_of :tags
Expand Down