diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-08-03 14:39:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-03 14:39:49 -0400 |
commit | 7d6990344e3d549ef451bc554d126aaa8544ac95 (patch) | |
tree | 768a1b5fbb695059ce83c131535d5821c5d1d585 /activerecord/lib/active_record/statement_cache.rb | |
parent | ec544350bb59e9e42361d607bde2db689c6bb2d7 (diff) | |
parent | 510428ff64ce19340913145140986119c64c8b7d (diff) | |
download | rails-7d6990344e3d549ef451bc554d126aaa8544ac95.tar.gz rails-7d6990344e3d549ef451bc554d126aaa8544ac95.tar.bz2 rails-7d6990344e3d549ef451bc554d126aaa8544ac95.zip |
Merge pull request #30050 from kamipo/dont_pass_connection_to_statement_cache_execute
Passing `klass` to `StatementCache.new`
Diffstat (limited to 'activerecord/lib/active_record/statement_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index 2af7d00246..59acd63a0f 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -11,7 +11,7 @@ module ActiveRecord # The cached statement is executed by using the # {connection.execute}[rdoc-ref:ConnectionAdapters::DatabaseStatements#execute] method: # - # cache.execute([], Book, Book.connection) + # cache.execute([], Book.connection) # # The relation returned by the block is cached, and for each # {execute}[rdoc-ref:ConnectionAdapters::DatabaseStatements#execute] @@ -26,7 +26,7 @@ module ActiveRecord # # And pass the bind values as the first argument of +execute+ call. # - # cache.execute(["my book"], Book, Book.connection) + # cache.execute(["my book"], Book.connection) class StatementCache # :nodoc: class Substitute; end # :nodoc: @@ -87,21 +87,20 @@ module ActiveRecord end end - attr_reader :bind_map, :query_builder - def self.create(connection, block = Proc.new) relation = block.call Params.new query_builder, binds = connection.cacheable_query(self, relation.arel) bind_map = BindMap.new(binds) - new query_builder, bind_map + new(query_builder, bind_map, relation.klass) end - def initialize(query_builder, bind_map) + def initialize(query_builder, bind_map, klass) @query_builder = query_builder - @bind_map = bind_map + @bind_map = bind_map + @klass = klass end - def execute(params, klass, connection, &block) + def execute(params, connection, &block) bind_values = bind_map.bind params sql = query_builder.sql_for bind_values, connection @@ -114,5 +113,9 @@ module ActiveRecord when NilClass, Array, Range, Hash, Relation, Base then true end end + + protected + + attr_reader :query_builder, :bind_map, :klass end end |