aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorFrederick Cheung <frederick.cheung@gmail.com>2008-08-25 22:36:19 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2008-08-25 20:49:55 -0700
commitb7a37b742c0abd1df8ea48cc82f76385cc0c41ea (patch)
tree2f2956ee7d2da26c1c8e13ddb0489f5eaaf0e4e4 /activerecord/lib
parentf2d8d13c6495f2a9b3bbf3b50d869c0e5b25c207 (diff)
downloadrails-b7a37b742c0abd1df8ea48cc82f76385cc0c41ea.tar.gz
rails-b7a37b742c0abd1df8ea48cc82f76385cc0c41ea.tar.bz2
rails-b7a37b742c0abd1df8ea48cc82f76385cc0c41ea.zip
Fix preloading of has_one through associations
[#903 state:resolved] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/association_preload.rb8
1 files changed, 2 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index c7594809b7..61fa34ac39 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -51,9 +51,7 @@ module ActiveRecord
def add_preloaded_record_to_collection(parent_records, reflection_name, associated_record)
parent_records.each do |parent_record|
- association_proxy = parent_record.send(reflection_name)
- association_proxy.loaded
- association_proxy.target = associated_record
+ parent_record.send("set_#{reflection_name}_target", associated_record)
end
end
@@ -112,8 +110,8 @@ module ActiveRecord
def preload_has_one_association(records, reflection, preload_options={})
id_to_record_map, ids = construct_id_map(records)
options = reflection.options
+ records.each {|record| record.send("set_#{reflection.name}_target", nil)}
if options[:through]
- records.each {|record| record.send(reflection.name) && record.send(reflection.name).loaded}
through_records = preload_through_records(records, reflection, options[:through])
through_reflection = reflections[options[:through]]
through_primary_key = through_reflection.primary_key_name
@@ -126,8 +124,6 @@ module ActiveRecord
end
end
else
- records.each {|record| record.send("set_#{reflection.name}_target", nil)}
-
set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.primary_key_name)
end
end