diff options
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 252ff7e7ea..53ec5a0da6 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -110,6 +110,7 @@ module ActiveRecord # Resets the \loaded flag to +false+ and sets the \target to +nil+. def reset @loaded = false + IdentityMap.remove(@target) if defined?(@target) && @target && IdentityMap.enabled? @target = nil end @@ -253,7 +254,10 @@ module ActiveRecord return nil unless defined?(@loaded) if !loaded? && (!@owner.new_record? || foreign_key_present) - @target = find_target + if IdentityMap.enabled? && association_class + @target = IdentityMap.get(association_class, @owner[@reflection.association_foreign_key]) + end + @target ||= find_target end @loaded = true @@ -309,6 +313,10 @@ module ActiveRecord def we_can_set_the_inverse_on_this?(record) false end + + def association_class + @reflection.klass + end end end end |