diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 0637053464679fcc0900b8c2dc105b53f32e1571..d91dff960c6459b7523679afa6789fca41bd78d4 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -64,7 +64,10 @@ def not(opts, *rest) private def not_behaves_as_nor?(opts) - opts.is_a?(Hash) && opts.size > 1 + return false unless opts.is_a?(Hash) + + opts.any? { |k, v| v.is_a?(Hash) && v.size > 1 } || + opts.size > 1 end end diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index 417a50b3f61c49a28c7be68e88f84b0adbe54631..d3c69e6dac60a7b0c7d0ca9ef9bed2be4f6445c9 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -181,6 +181,18 @@ def test_where_not_polymorphic_id_and_type_as_nor_is_deprecated assert_equal all - expected, only.sort_by(&:id).map(&:estimate_of) end + def test_where_not_association_as_nor_is_deprecated + treasure = Treasure.create!(name: "my_treasure") + PriceEstimate.create!(estimate_of: treasure, price: 2, currency: "USD") + PriceEstimate.create(estimate_of: treasure, price: 2, currency: "EUR") + + assert_deprecated do + result = Treasure.joins(:price_estimates).where.not(price_estimates: { price: 2, currency: "USD" }) + + assert_predicate result, :empty? + end + end + def test_polymorphic_nested_array_where treasure = Treasure.new treasure.id = 1 diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index cae2890c9e1ba6ddee9c70a858bbba2ef0fa6fe8..fa682909192d98a481eba277ec4532f20f13d08e 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -746,6 +746,7 @@ t.string :estimate_of_type t.integer :estimate_of_id t.integer :price + t.string :currency end create_table :products, force: true do |t|