1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix where on polymorphic association with empty array

Fix for https://github.com/rails/rails/pull/40951#issuecomment-757078536.
This commit is contained in:
Ryuta Kamizono 2021-01-09 13:33:57 +09:00
parent 66a4cf4bbc
commit f90ef6cb07
3 changed files with 7 additions and 1 deletions

View file

@ -9,6 +9,8 @@ module ActiveRecord
end end
def queries def queries
return [ associated_table.join_foreign_key => values ] if values.empty?
type_to_ids_mapping.map do |type, ids| type_to_ids_mapping.map do |type, ids|
query = {} query = {}
query[associated_table.join_foreign_type] = type if type query[associated_table.join_foreign_type] = type if type

View file

@ -51,6 +51,10 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal comments(:greetings), Comment.where(author: [nil]).first assert_equal comments(:greetings), Comment.where(author: [nil]).first
end end
def test_where_on_polymorphic_association_with_empty_array
assert_empty Comment.where(author: [])
end
def test_assigning_belongs_to_on_destroyed_object def test_assigning_belongs_to_on_destroyed_object
client = Client.create!(name: "Client") client = Client.create!(name: "Client")
client.destroy! client.destroy!