aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/merger.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-15 16:29:01 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-15 16:29:01 -0700
commit9675c7da28758432ec7bd6e7ca1814801b2591f5 (patch)
tree39219fc8b144defc071738cfa0d3cdf00182aa40 /activerecord/lib/active_record/relation/merger.rb
parentd345ed40b5783ec2cb43f4434872ea5b2d57d203 (diff)
downloadrails-9675c7da28758432ec7bd6e7ca1814801b2591f5.tar.gz
rails-9675c7da28758432ec7bd6e7ca1814801b2591f5.tar.bz2
rails-9675c7da28758432ec7bd6e7ca1814801b2591f5.zip
reorder bind parameters when merging relations
Diffstat (limited to 'activerecord/lib/active_record/relation/merger.rb')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index f5d668dae8..da13152e01 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -97,13 +97,29 @@ module ActiveRecord
def merge_multi_values
lhs_wheres = relation.where_values
rhs_wheres = values[:where] || []
+
lhs_binds = relation.bind_values
rhs_binds = values[:bind] || []
removed, kept = partition_overwrites(lhs_wheres, rhs_wheres)
- relation.where_values = kept + rhs_wheres
- relation.bind_values = filter_binds(lhs_binds, removed) + rhs_binds
+ where_values = kept + rhs_wheres
+ bind_values = filter_binds(lhs_binds, removed) + rhs_binds
+
+ conn = relation.klass.connection
+ bviter = bind_values.each.with_index
+ where_values.map! do |node|
+ if Arel::Nodes::Equality === node && Arel::Nodes::BindParam === node.right
+ (column, _), i = bviter.next
+ substitute = conn.substitute_at column, i
+ Arel::Nodes::Equality.new(node.left, substitute)
+ else
+ node
+ end
+ end
+
+ relation.where_values = where_values
+ relation.bind_values = bind_values
if values[:reordering]
# override any order specified in the original relation