diff options
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/aggregations.rb | 6 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 0970eaceee..314c40cfde 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -4,6 +4,12 @@ module ActiveRecord base.extend(ClassMethods) end + def clear_aggregation_cache #:nodoc: + self.class.reflect_on_all_aggregations.to_a.each do |assoc| + instance_variable_set "@#{assoc.name}", nil + end unless self.new_record? + 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 to the macro adds a description of how the value objects are created from the diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 27b2de6f8d..b8925a6ee5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1309,6 +1309,7 @@ module ActiveRecord #:nodoc: # Reloads the attributes of this object from the database. def reload + clear_aggregation_cache clear_association_cache @attributes.update(self.class.find(self.id).instance_variable_get('@attributes')) self |