diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 13:42:02 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 16:10:03 -0700 |
commit | b06f64c3480cd389d14618540d62da4978918af0 (patch) | |
tree | 626a163d2885fd3b91e58c6bcbf60ec3824a51f0 /activerecord/lib/active_record/statement_cache.rb | |
parent | d66ffb656e0cfbb4216f030c8e0669509567e362 (diff) | |
download | rails-b06f64c3480cd389d14618540d62da4978918af0.tar.gz rails-b06f64c3480cd389d14618540d62da4978918af0.tar.bz2 rails-b06f64c3480cd389d14618540d62da4978918af0.zip |
Remove Relation#bind_params
`bound_attributes` is now used universally across the board, removing
the need for the conversion layer. These changes are mostly mechanical,
with the exception of the log subscriber. Additional, we had to
implement `hash` on the attribute objects, so they could be used as a
key for query caching.
Diffstat (limited to 'activerecord/lib/active_record/statement_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index 3047a81ec4..95986c820c 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -48,7 +48,7 @@ module ActiveRecord def sql_for(binds, connection) val = @values.dup binds = connection.prepare_binds_for_database(binds) - @indexes.each { |i| val[i] = connection.quote(binds.shift.last) } + @indexes.each { |i| val[i] = connection.quote(binds.shift) } val.join end end @@ -67,21 +67,21 @@ module ActiveRecord end class BindMap # :nodoc: - def initialize(bind_values) + def initialize(bound_attributes) @indexes = [] - @bind_values = bind_values + @bound_attributes = bound_attributes - bind_values.each_with_index do |(_, value), i| - if Substitute === value + bound_attributes.each_with_index do |attr, i| + if Substitute === attr.value @indexes << i end end end def bind(values) - bvs = @bind_values.map(&:dup) - @indexes.each_with_index { |offset,i| bvs[offset][1] = values[i] } - bvs + bas = @bound_attributes.dup + @indexes.each_with_index { |offset,i| bas[offset] = bas[offset].with_cast_value(values[i]) } + bas end end @@ -89,7 +89,7 @@ module ActiveRecord def self.create(connection, block = Proc.new) relation = block.call Params.new - bind_map = BindMap.new relation.bind_values + bind_map = BindMap.new relation.bound_attributes query_builder = connection.cacheable_query relation.arel new query_builder, bind_map end |