aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 78da6a83ec..fc653f467c 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -384,6 +384,9 @@ module ActiveRecord
end
end
+ #For bind param caching. TODO: VALIDATE AND CORRECT THIS
+ self.bind_values = []
+ #end
self
end
@@ -827,7 +830,7 @@ module ActiveRecord
build_joins(arel, joins_values.flatten) unless joins_values.empty?
- collapse_wheres(arel, (where_values - ['']).uniq)
+ collapse_wheres(arel, (where_values - [''])) #TODO: Add uniq with real value comparison / ignore uniqs that have binds
arel.having(*having_values.uniq.reject(&:blank?)) unless having_values.empty?
@@ -920,9 +923,14 @@ module ActiveRecord
[@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
when Hash
+ temp_opts = opts.dup
opts = PredicateBuilder.resolve_column_aliases(klass, opts)
attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)
+ create_binds(temp_opts)
+ temp_opts = substitute_opts(temp_opts)
+
+ attributes = @klass.send(:expand_hash_conditions_for_aggregates, temp_opts)
attributes.values.grep(ActiveRecord::Relation) do |rel|
self.bind_values += rel.bind_values
end
@@ -933,6 +941,30 @@ module ActiveRecord
end
end
+ def create_binds(temp_opts)
+ binds = []
+ temp_opts.map 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
+ 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
+ end
+ end
+
def build_from
opts, name = from_value
case opts