diff options
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/association_preload.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 313c51dae0..a89f5f5459 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -162,12 +162,13 @@ module ActiveRecord # Construct a mapping from klass to a list of ids to load and a mapping of those ids back to their parent_records records.each do |record| - klass = record.send(polymorph_type) - klass_id = record.send(primary_key_name) + if klass = record.send(polymorph_type) + klass_id = record.send(primary_key_name) - id_map = klasses_and_ids[klass] ||= {} - id_list_for_klass_id = (id_map[klass_id] ||= []) - id_list_for_klass_id << record + id_map = klasses_and_ids[klass] ||= {} + id_list_for_klass_id = (id_map[klass_id] ||= []) + id_list_for_klass_id << record + end end klasses_and_ids = klasses_and_ids.to_a else |