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

Fix where on polymorphic association with empty array #41063

Merged
Merged
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
Expand Up @@ -9,7 +9,7 @@ def initialize(associated_table, value)
end

def queries
[associated_table.join_foreign_key => ids]
[ associated_table.join_foreign_key => ids ]
end

private
Expand Down
Expand Up @@ -9,6 +9,8 @@ def initialize(associated_table, values)
end

def queries
return [ associated_table.join_foreign_key => values ] if values.empty?

type_to_ids_mapping.map do |type, ids|
query = {}
query[associated_table.join_foreign_type] = type if type
Expand Down
Expand Up @@ -51,6 +51,10 @@ def test_where_on_polymorphic_association_with_nil
assert_equal comments(:greetings), Comment.where(author: [nil]).first
end

def test_where_on_polymorphic_association_with_empty_array
assert_empty Comment.where(author: [])
end

def test_assigning_belongs_to_on_destroyed_object
client = Client.create!(name: "Client")
client.destroy!
Expand Down