提交 b381bff6 编写于 作者: R Ryuta Kamizono

Merge pull request #37598 from Edouard-chin/ec-where-not-relation-deprecated

Correctly deprecate where.not working as NOR for relations:
上级 81c52b13
......@@ -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
......
......@@ -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
......
......@@ -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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册