diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 4396dab54e..c7ab926f56 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -116,10 +116,11 @@ module ActiveRecord end def preload_hash(association, records) - association.flat_map { |parent, child| - preload_one parent, records - run_preload Array.wrap(child), records.map { |record| record.send(parent) }.flatten.compact.uniq - } + parent, child = association.to_a.first # hash should only be of length 1 + + preload_one parent, records + run_preload Array.wrap(child), + records.map { |record| record.send(parent) }.flatten.compact.uniq end # Not all records have the same class, so group then preload group on the reflection |