diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-18 14:49:02 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-18 14:49:02 -0800 |
commit | 248391a7e11e9fa5ffe312cb380034691430acc5 (patch) | |
tree | 0d151f54139732c417f3d4242e13f1aac64ac858 /activerecord/lib/active_record/association_preload.rb | |
parent | 86abd6887dac9ee233740399f9e5758309af512e (diff) | |
parent | a9422cc1db9501a80ecf2c25a5d3b0c4f4f32763 (diff) | |
download | rails-248391a7e11e9fa5ffe312cb380034691430acc5.tar.gz rails-248391a7e11e9fa5ffe312cb380034691430acc5.tar.bz2 rails-248391a7e11e9fa5ffe312cb380034691430acc5.zip |
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r-- | activerecord/lib/active_record/association_preload.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 99c3ce5e62..7b1b2d9ad9 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -204,9 +204,18 @@ module ActiveRecord unless through_records.empty? source = reflection.source_reflection.name through_records.first.class.preload_associations(through_records, source) - 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)) + if through_reflection.macro == :belongs_to + rev_id_to_record_map, rev_ids = construct_id_map(records, through_primary_key) + 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 end end else @@ -307,6 +316,7 @@ module ActiveRecord klasses_and_ids.each do |klass_and_id| klass_name, id_map = *klass_and_id + next if id_map.empty? klass = klass_name.constantize table_name = klass.quoted_table_name |