diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2013-05-08 17:05:06 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2013-05-08 17:05:06 -0700 |
commit | c0df1e8c08a27a7de489dad7492015d68f2c76f7 (patch) | |
tree | a4f7a25d965ebcce118e808d26f3075fff10be40 /activerecord/lib | |
parent | 05609f472912cc841d99e3b0adb18c4f3d0eb9ae (diff) | |
parent | fdba949b47154f43aa8d0cce5177a75080f47836 (diff) | |
download | rails-c0df1e8c08a27a7de489dad7492015d68f2c76f7.tar.gz rails-c0df1e8c08a27a7de489dad7492015d68f2c76f7.tar.bz2 rails-c0df1e8c08a27a7de489dad7492015d68f2c76f7.zip |
Merge pull request #10523 from neerajdotname/last-where-clause-wins
Extraction to enable fixing #10421
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 936b83261e..bda7a76330 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -139,21 +139,20 @@ module ActiveRecord if values[:where].empty? || relation.where_values.empty? relation.where_values + values[:where] else - # Remove equalities from the existing relation with a LHS which is - # present in the relation being merged in. + sanitized_wheres + values[:where] + end + end - seen = Set.new - values[:where].each { |w| - if w.respond_to?(:operator) && w.operator == :== - seen << w.left - end - } + # Remove equalities from the existing relation with a LHS which is + # present in the relation being merged in. + def sanitized_wheres + seen = Set.new + values[:where].each do |w| + seen << w.left if w.respond_to?(:operator) && w.operator == :== + end - relation.where_values.reject { |w| - w.respond_to?(:operator) && - w.operator == :== && - seen.include?(w.left) - } + values[:where] + relation.where_values.reject do |w| + w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) end end end |