From fdba949b47154f43aa8d0cce5177a75080f47836 Mon Sep 17 00:00:00 2001
From: Neeraj Singh <neerajdotname@gmail.com>
Date: Wed, 8 May 2013 14:20:06 -0400
Subject: extracted piece of code into a method

In order to fix #10421 I need to enable merge to take an option
so that relations could be merged without making the last where
condition to win.

That fix would forever reside in 4-0-stable branch and would not be
merged to master since using scope without lambda has been deprecated.

In this commit I have extracted code into a method and I think it
makes code look better. Hence the request to merge it in both
master and 4-0-stable.

If there is any concern then this code can be merged only in
4-0-stable and that would be fine too.
---
 activerecord/lib/active_record/relation/merger.rb | 25 +++++++++++------------
 1 file changed, 12 insertions(+), 13 deletions(-)

(limited to 'activerecord')

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
-- 
cgit v1.2.3