aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-21 10:35:35 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-21 10:35:35 -0700
commita483ae6477fab482e95b3415bb9b0cf54f198699 (patch)
tree3ecde93631cd4fbdead7bbfb8565bdab43f49a35 /activerecord
parent847752a295d411ccff31f3137c140ec0f5445c07 (diff)
downloadrails-a483ae6477fab482e95b3415bb9b0cf54f198699.tar.gz
rails-a483ae6477fab482e95b3415bb9b0cf54f198699.tar.bz2
rails-a483ae6477fab482e95b3415bb9b0cf54f198699.zip
push partion logic down and initialization logic up
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb26
1 files changed, 11 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 58ac239190..eb72d551da 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -99,7 +99,10 @@ module ActiveRecord
end
def merge_multi_values
- relation.where_values = merged_wheres
+ rhs_wheres = values[:where] || []
+ lhs_wheres = relation.where_values
+
+ relation.where_values = merged_wheres(lhs_wheres, rhs_wheres)
relation.bind_values = merged_binds
if values[:reordering]
@@ -131,30 +134,23 @@ module ActiveRecord
end
end
- def merged_wheres
- rhs_wheres = values[:where] || []
- lhs_wheres = relation.where_values
-
- if rhs_wheres.empty? || lhs_wheres.empty?
- lhs_wheres + rhs_wheres
- else
- reject_overwrites(lhs_wheres, rhs_wheres) + rhs_wheres
- end
+ def merged_wheres(lhs_wheres, rhs_wheres)
+ partition_overwrites(lhs_wheres, rhs_wheres).last + rhs_wheres
end
# 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
-
+ # returns [things_to_remove, things_to_keep]
def partition_overwrites(lhs_wheres, rhs_wheres)
+ if lhs_wheres.empty? || rhs_wheres.empty?
+ return [[], lhs_wheres]
+ end
+
nodes = rhs_wheres.find_all do |w|
w.respond_to?(:operator) && w.operator == :==
end
seen = Set.new(nodes) { |node| node.left }
- # returns [deleted, keepers]
lhs_wheres.partition do |w|
w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left)
end