diff options
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index cdc8f25119..371dad9104 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -119,6 +119,12 @@ module ActiveRecord # Clears out the association cache. def clear_association_cache #:nodoc: self.class.reflect_on_all_associations.to_a.each do |assoc| + if IdentityMap.enabled? && instance_variable_defined?("@#{assoc.name}") + Array(instance_variable_get("@#{assoc.name}")).each do |t| + next unless t.respond_to?(:target) + IdentityMap.remove t.target unless t.target.nil? + end + end instance_variable_set "@#{assoc.name}", nil end if self.persisted? end |