aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r--activerecord/lib/active_record/associations.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 08a4ebfd7e..12b0601e3c 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -117,6 +117,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}")
+ targets = [*instance_variable_get("@#{assoc.name}")]
+ targets.map! { |t| t.respond_to?(:target) ? t.target : t }
+ targets.compact!
+ targets.each { |r| IdentityMap.remove r }
+ end
instance_variable_set "@#{assoc.name}", nil
end if self.persisted?
end