Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

take in to account existing bind parameters when building the bind list

  • Loading branch information...
commit 58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c 1 parent b6c7275
@tenderlove tenderlove authored
Showing with 20 additions and 21 deletions.
  1. +20 −21 activerecord/lib/active_record/relation/query_methods.rb
View
41 activerecord/lib/active_record/relation/query_methods.rb
@@ -919,13 +919,13 @@ def build_where(opts, other = [])
[@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 @@ def build_where(opts, other = [])
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
Please sign in to comment.
Something went wrong with that request. Please try again.