aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-01-14 16:21:10 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-01-14 16:21:10 -0800
commit58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c (patch)
tree52161bed42f4948a23f6e02d1393fd444389de46 /activerecord/lib/active_record/relation
parentb6c7275e0cb2e58ac35f4c9fecd5236dd6ab6d81 (diff)
downloadrails-58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c.tar.gz
rails-58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c.tar.bz2
rails-58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c.zip
take in to account existing bind parameters when building the bind list
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb41
1 files changed, 20 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 028043fece..159ad1dbe3 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -919,13 +919,13 @@ module ActiveRecord
[@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
when Hash
opts = PredicateBuilder.resolve_column_aliases(klass, opts)
- temp_opts = opts.dup
attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)
- create_binds(temp_opts)
- temp_opts = substitute_opts(temp_opts)
+ bv_len = bind_values.length
+ tmp_opts, bind_values = create_binds(opts, bv_len)
+ self.bind_values += bind_values
- attributes = @klass.send(:expand_hash_conditions_for_aggregates, temp_opts)
+ attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
attributes.values.grep(ActiveRecord::Relation) do |rel|
self.bind_values += rel.bind_values
end
@@ -936,28 +936,27 @@ module ActiveRecord
end
end
- def create_binds(temp_opts)
- binds = []
- temp_opts.map do |column, value|
+ def create_binds(opts, idx)
+ bindable, non_binds = opts.partition do |column, value|
case value
- when String, Integer
- if @klass.column_names.include? column.to_s
- binds.push([@klass.columns_hash[column.to_s], value])
- end
+ when String, Integer
+ @klass.columns_hash.include? column.to_s
+ else
+ false
end
end
- self.bind_values += binds
- end
- def substitute_opts(temp_opts)
- temp_opts = temp_opts.each_with_index do |(column,value), index|
- if @klass.columns_hash[column.to_s] != nil
- case value
- when String, Integer
- temp_opts[column] = connection.substitute_at(column, index)
- end
- end
+ new_opts = {}
+ binds = []
+
+ bindable.each_with_index do |(column,value), index|
+ binds.push [@klass.columns_hash[column.to_s], value]
+ new_opts[column] = connection.substitute_at(column, index + idx)
end
+
+ non_binds.each { |column,value| new_opts[column] = value }
+
+ [new_opts, binds]
end
def build_from