Skip to content
This repository
Browse code

Remove associated objects from IM when clearing them from association…

… cache.
  • Loading branch information...
commit 5ee3663101f224a30ec95f6dab4b02a4a922eb2f 1 parent 095c445
Emilio Tagua authored October 20, 2010
6  activerecord/lib/active_record/associations.rb
@@ -117,6 +117,12 @@ module Associations # :nodoc:
117 117
     # Clears out the association cache.
118 118
     def clear_association_cache #:nodoc:
119 119
       self.class.reflect_on_all_associations.to_a.each do |assoc|
  120
+        if IdentityMap.enabled? && instance_variable_defined?("@#{assoc.name}")
  121
+          targets = [*instance_variable_get("@#{assoc.name}")]
  122
+          targets.map! { |t| t.respond_to?(:target) ? t.target : t }
  123
+          targets.compact!
  124
+          targets.each { |r| IdentityMap.remove r }
  125
+        end
120 126
         instance_variable_set "@#{assoc.name}", nil
121 127
       end if self.persisted?
122 128
     end

0 notes on commit 5ee3663

Please sign in to comment.
Something went wrong with that request. Please try again.