diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index <HASH>..<HASH> 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -145,12 +145,17 @@ module ActiveRecord
       # Remove equalities from the existing relation with a LHS which is
       # present in the relation being merged in.
       def reject_overwrites(lhs_wheres, rhs_wheres)
+        partition_overwrites(lhs_wheres, rhs_wheres).last
+      end
+
+      def partition_overwrites(lhs_wheres, rhs_wheres)
         nodes = rhs_wheres.find_all do |w|
           w.respond_to?(:operator) && w.operator == :==
         end
         seen = Set.new(nodes) { |node| node.left }
 
-        lhs_wheres.reject do |w|
+        # returns [deleted, keepers]
+        lhs_wheres.partition do |w|
           w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left)
         end
       end
partition the where values so we can access the removed ones