From 48634bf59a0ed89cddd4a539c08866c9e025c5e3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 7 Apr 2010 01:16:45 +0100 Subject: Reset named scope cache whenever the @target is reset --- .../lib/active_record/associations/association_collection.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations/association_collection.rb') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 5ecdf1ac8d..c1ec98a9c6 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -105,6 +105,7 @@ module ActiveRecord def reset reset_target! + reset_named_scopes_cache! @loaded = false end @@ -162,6 +163,7 @@ module ActiveRecord load_target delete(@target) reset_target! + reset_named_scopes_cache! end # Calculate sum using SQL, not Enumerable @@ -250,6 +252,7 @@ module ActiveRecord load_target destroy(@target) reset_target! + reset_named_scopes_cache! end def create(attrs = {}) @@ -406,8 +409,8 @@ module ActiveRecord super end elsif @reflection.klass.scopes[method] - @_scopes ||= {} - @_scopes[method] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) } + @_named_scopes_cache ||= {} + @_named_scopes_cache[method] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) } else with_scope(construct_scope) do if block_given? @@ -428,6 +431,10 @@ module ActiveRecord @target = Array.new end + def reset_named_scopes_cache! + @_named_scopes_cache = {} + end + def find_target records = if @reflection.options[:finder_sql] -- cgit v1.2.3