Skip to content
Browse files

partition the where values so we can access the removed ones

  • Loading branch information...
1 parent bff89a2 commit 847752a295d411ccff31f3137c140ec0f5445c07 @tenderlove tenderlove committed May 20, 2013
Showing with 6 additions and 1 deletion.
  1. +6 −1 activerecord/lib/active_record/relation/merger.rb
View
7 activerecord/lib/active_record/relation/merger.rb
@@ -145,12 +145,17 @@ def merged_wheres
# 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

0 comments on commit 847752a

Please sign in to comment.
Something went wrong with that request. Please try again.