diff options
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r-- | activerecord/lib/active_record/association_preload.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 9ef8ed15e8..313c51dae0 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -34,7 +34,11 @@ module ActiveRecord reflection = reflections[association] raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection - send(:"preload_#{reflection.macro}_association", records, reflection, preload_options) + # Not all records have the same class, so group then preload. + records.group_by(&:class).each do |klass, records| + reflection = klass.reflections[association] + send("preload_#{reflection.macro}_association", records, reflection, preload_options) + end end def add_preloaded_records_to_collection(parent_records, reflection_name, associated_record) |