From 234bbe5cb0e31b786cc73e8f63e55a9ce8aecf88 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 15 Sep 2010 15:38:38 -0300 Subject: Associated objects are assigned from identity map if enabled and contains associated object. --- activerecord/lib/active_record/associations/association_proxy.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 7cd04a1ad5..bfedffcf02 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -252,8 +252,11 @@ module ActiveRecord def load_target return nil unless defined?(@loaded) - if !loaded? and (@owner.persisted? || foreign_key_present) - @target = find_target + if !loaded? and (!@owner.persisted? || foreign_key_present) + if IdentityMap.enabled? + @target = IdentityMap.get(@reflection.class_name, @owner[@reflection.association_foreign_key]) + end + @target ||= find_target end @loaded = true -- cgit v1.2.3