aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-21 19:27:23 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-21 19:27:23 -0700
commit19ff42d909bd11512ffaad12031d7127fa9b5d8c (patch)
treed9216fb092d6d08d123420535c7cc8bec0a34e33 /activerecord
parent79ef26c8c99985f9b438df8822635d8f0ea36fa2 (diff)
downloadrails-19ff42d909bd11512ffaad12031d7127fa9b5d8c.tar.gz
rails-19ff42d909bd11512ffaad12031d7127fa9b5d8c.tar.bz2
rails-19ff42d909bd11512ffaad12031d7127fa9b5d8c.zip
deleting repeated codes
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/association_preload.rb23
1 files changed, 10 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 63224377a3..82d8c77242 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -209,23 +209,20 @@ module ActiveRecord
records.each {|record| record.send("set_#{reflection.name}_target", nil)}
if options[:through]
through_records = preload_through_records(records, reflection, options[:through])
- through_reflection = reflections[options[:through]]
- through_primary_key = through_reflection.primary_key_name
+
unless through_records.empty?
+ through_reflection = reflections[options[:through]]
+ through_primary_key = through_reflection.primary_key_name
source = reflection.source_reflection.name
through_records.first.class.preload_associations(through_records, source)
if through_reflection.macro == :belongs_to
- rev_id_to_record_map = construct_id_map(records, through_primary_key).first
- rev_primary_key = through_reflection.klass.primary_key
- through_records.each do |through_record|
- add_preloaded_record_to_collection(rev_id_to_record_map[through_record[rev_primary_key].to_s],
- reflection.name, through_record.send(source))
- end
- else
- through_records.each do |through_record|
- add_preloaded_record_to_collection(id_to_record_map[through_record[through_primary_key].to_s],
- reflection.name, through_record.send(source))
- end
+ id_to_record_map = construct_id_map(records, through_primary_key).first
+ through_primary_key = through_reflection.klass.primary_key
+ end
+
+ through_records.each do |through_record|
+ add_preloaded_record_to_collection(id_to_record_map[through_record[through_primary_key].to_s],
+ reflection.name, through_record.send(source))
end
end
else