Permalink
Browse files

Remove associated objects from IM when clearing them from association…

… cache.
  • Loading branch information...
1 parent 095c445 commit 5ee3663101f224a30ec95f6dab4b02a4a922eb2f @miloops miloops committed Oct 20, 2010
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/associations.rb
@@ -117,6 +117,12 @@ module Associations # :nodoc:
# 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

0 comments on commit 5ee3663

Please sign in to comment.