aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/aggregations.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-20 17:45:10 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-20 17:45:10 -0200
commit37bef5827f94137f4542cacc669e9c3ce6c9495d (patch)
tree3c0b9379da5e2f68a459e52ac0910e51ee0bf85c /activerecord/lib/active_record/aggregations.rb
parent192d319fdbb5b1575b5541bb5395c87d87fadfa1 (diff)
parent9d569585a20ddd9ddb3602921f2ccffc208998d8 (diff)
downloadrails-37bef5827f94137f4542cacc669e9c3ce6c9495d.tar.gz
rails-37bef5827f94137f4542cacc669e9c3ce6c9495d.tar.bz2
rails-37bef5827f94137f4542cacc669e9c3ce6c9495d.zip
Merge pull request #16989 from Empact/reload-cache-clear
Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
Diffstat (limited to 'activerecord/lib/active_record/aggregations.rb')
-rw-r--r--activerecord/lib/active_record/aggregations.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 39077aea7e..5d723d6648 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")