diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2014-09-20 09:03:03 -0700 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2014-09-28 16:17:06 -0700 |
commit | 9d569585a20ddd9ddb3602921f2ccffc208998d8 (patch) | |
tree | 97f5ee9a38a958f3bf60c1f1f972b8549f9cedb5 /activerecord/lib/active_record/aggregations.rb | |
parent | 482e80e84440136763b47c0fba2ed65a7823f022 (diff) | |
download | rails-9d569585a20ddd9ddb3602921f2ccffc208998d8.tar.gz rails-9d569585a20ddd9ddb3602921f2ccffc208998d8.tar.bz2 rails-9d569585a20ddd9ddb3602921f2ccffc208998d8.zip |
Isolate access to @associations_cache and @aggregations cache to the Associations and Aggregations modules, respectively.
This includes replacing the `association_cache` accessor with a more
limited `association_cached?` accessor and making `clear_association_cache`
and `clear_aggregation_cache` private.
Diffstat (limited to 'activerecord/lib/active_record/aggregations.rb')
-rw-r--r-- | activerecord/lib/active_record/aggregations.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index e576ec4d40..b2e83824be 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -3,10 +3,27 @@ module ActiveRecord module Aggregations # :nodoc: extend ActiveSupport::Concern - def clear_aggregation_cache #:nodoc: - @aggregation_cache.clear if persisted? + def initialize_dup(*) # :nodoc: + @aggregation_cache = {} + super end + def reload(*) # :nodoc: + clear_aggregation_cache + super + end + + private + + def clear_aggregation_cache # :nodoc: + @aggregation_cache.clear if persisted? + end + + def init_internals # :nodoc: + @aggregation_cache = {} + super + end + # Active Record implements aggregation through a macro-like class method called +composed_of+ # for representing attributes as value objects. It expresses relationships like "Account [is] # composed of Money [among other things]" or "Person [is] composed of [an] address". Each call @@ -89,7 +106,7 @@ module ActiveRecord # # customer.address_street = "Vesterbrogade" # customer.address # => Address.new("Hyancintvej", "Copenhagen") - # customer.clear_aggregation_cache + # customer.send(:clear_aggregation_cache) # customer.address # => Address.new("Vesterbrogade", "Copenhagen") # # customer.address = Address.new("May Street", "Chicago") |