From 18dccdccf75e4084718622f578a1ff98f2da6955 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 20 Sep 2013 14:23:56 -0700 Subject: the hash should only ever be length one, so decompose it --- activerecord/lib/active_record/associations/preloader.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3