diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 4 |
2 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 1b7f579aa3..269675192a 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -135,7 +135,7 @@ module ActiveRecord key = primary_key s = find_by_statement_cache[key] || find_by_statement_cache.synchronize { - find_by_statement_cache[key] ||= StatementCache.create { |params| + find_by_statement_cache[key] ||= StatementCache.create(connection) { |params| where(key => params[key]).limit(1) } } @@ -159,7 +159,7 @@ module ActiveRecord klass = self s = find_by_statement_cache[key] || find_by_statement_cache.synchronize { - find_by_statement_cache[key] ||= StatementCache.create { |params| + find_by_statement_cache[key] ||= StatementCache.create(connection) { |params| wheres = key.each_with_object({}) { |param,o| o[param] = params[param] } diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index fbba95d78f..d6c48125f4 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -76,11 +76,9 @@ module ActiveRecord attr_reader :bind_map, :query_builder - def self.create(block = Proc.new) + def self.create(connection, block = Proc.new) relation = block.call Params.new bind_map = BindMap.new relation.bind_values - klass = relation.klass - connection = klass.connection query_builder = connection.cacheable_query relation.arel new query_builder, bind_map end |