diff options
Diffstat (limited to 'activerecord/lib/active_record/statement_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index b03ff9bc6c..db7e0c8a04 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -41,18 +41,20 @@ module ActiveRecord end class PartialQuery < Query # :nodoc: - def initialize(values) - @values = values - @indexes = values.each_with_index.find_all { |thing, i| - Arel::Nodes::BindParam === thing - }.map(&:last) + def initialize(arel) + @arel = arel end def sql_for(binds, connection) - val = @values.dup - casted_binds = binds.map(&:value_for_database) - @indexes.each { |i| val[i] = connection.quote(casted_binds.shift) } - val.join + val = @arel.dup + val.grep(Arel::Nodes::BindParam) do |node| + node.value = binds.shift + if binds.empty? + break + end + end + sql, _ = connection.visitor.accept(val, connection.send(:collector)).value + sql end end @@ -90,9 +92,9 @@ module ActiveRecord attr_reader :bind_map, :query_builder def self.create(connection, block = Proc.new) - relation = block.call Params.new - bind_map = BindMap.new relation.bound_attributes - query_builder = connection.cacheable_query(self, relation.arel) + relation = block.call Params.new + query_builder, binds = connection.cacheable_query(self, relation.arel) + bind_map = BindMap.new(binds) new query_builder, bind_map end |