aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-20 18:02:46 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-20 18:02:46 -0700
commit847752a295d411ccff31f3137c140ec0f5445c07 (patch)
treed1157e25053ef379319d3e4a3c97ae1f2dcc26ae /activerecord
parentbff89a2022aedec60929f6d6744eefc84a5c102a (diff)
downloadrails-847752a295d411ccff31f3137c140ec0f5445c07.tar.gz
rails-847752a295d411ccff31f3137c140ec0f5445c07.tar.bz2
rails-847752a295d411ccff31f3137c140ec0f5445c07.zip
partition the where values so we can access the removed ones
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 98afeb8cc5..58ac239190 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