diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 14:23:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 14:23:56 -0700 |
commit | 18dccdccf75e4084718622f578a1ff98f2da6955 (patch) | |
tree | 83b251a2d44d80db5cea9ea1945a3aaaf1f2b7f6 /activerecord/lib | |
parent | 7a8904353c4482709350e0fe018391cc080c38d2 (diff) | |
download | rails-18dccdccf75e4084718622f578a1ff98f2da6955.tar.gz rails-18dccdccf75e4084718622f578a1ff98f2da6955.tar.bz2 rails-18dccdccf75e4084718622f578a1ff98f2da6955.zip |
the hash should only ever be length one, so decompose it
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 |