diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-04-07 01:16:45 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-04-07 01:16:45 +0100 |
commit | 48634bf59a0ed89cddd4a539c08866c9e025c5e3 (patch) | |
tree | ac4526ffd409f5b24f2671b5579908ab12d006dc /activerecord/lib/active_record/associations | |
parent | eb063538bd58c915c953e4b8a295d3a1b1a321d5 (diff) | |
download | rails-48634bf59a0ed89cddd4a539c08866c9e025c5e3.tar.gz rails-48634bf59a0ed89cddd4a539c08866c9e025c5e3.tar.bz2 rails-48634bf59a0ed89cddd4a539c08866c9e025c5e3.zip |
Reset named scope cache whenever the @target is reset
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 11 |
1 files changed, 9 insertions, 2 deletions
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] |