mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix merging NOT IN clause to behave the same as before
`HomogeneousIn` has changed merging behavior for NOT IN clause from before. This changes `equality?` to return true only if `type == :in` to restore the original behavior.
This commit is contained in:
parent
972f22e42a
commit
13a3f62ae8
2 changed files with 11 additions and 1 deletions
|
@ -21,7 +21,7 @@ module Arel # :nodoc: all
|
|||
alias :== :eql?
|
||||
|
||||
def equality?
|
||||
true
|
||||
type == :in
|
||||
end
|
||||
|
||||
def invert
|
||||
|
|
|
@ -88,6 +88,16 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|||
assert_equal [david, mary], mary_and_bob.merge(david_and_mary, rewhere: true)
|
||||
end
|
||||
|
||||
def test_merge_not_in_clause
|
||||
david, mary, bob = authors(:david, :mary, :bob)
|
||||
|
||||
non_mary_and_bob = Author.where.not(id: [mary, bob])
|
||||
|
||||
assert_equal [david], non_mary_and_bob
|
||||
assert_equal [david], Author.where(id: david).merge(non_mary_and_bob)
|
||||
assert_equal [], Author.where(id: mary).merge(non_mary_and_bob)
|
||||
end
|
||||
|
||||
def test_relation_merging
|
||||
devs = Developer.where("salary >= 80000").merge(Developer.limit(2)).merge(Developer.order("id ASC").where("id < 3"))
|
||||
assert_equal [developers(:david), developers(:jamis)], devs.to_a
|
||||
|
|
Loading…
Reference in a new issue