diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-20 10:16:57 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-20 10:16:57 -0700 |
commit | b713e207d470fe01ce8ea945163c6c2540292301 (patch) | |
tree | 6798a1a36c8d538c8e42dafc713ad2e7049e12ac /activerecord/lib/active_record/associations | |
parent | 9d835fd7f23138b90490f47df9920c62dceb7356 (diff) | |
download | rails-b713e207d470fe01ce8ea945163c6c2540292301.tar.gz rails-b713e207d470fe01ce8ea945163c6c2540292301.tar.bz2 rails-b713e207d470fe01ce8ea945163c6c2540292301.zip |
fix multiple hash preloads. Fixes #14994
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 20bd4947dc..42571d6af0 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -112,13 +112,14 @@ module ActiveRecord end def preloaders_for_hash(association, records, scope) - parent, child = association.to_a.first # hash should only be of length 1 + association.flat_map { |parent, child| + loaders = preloaders_for_one parent, records, scope - loaders = preloaders_for_one parent, records, scope - - recs = loaders.flat_map(&:preloaded_records).uniq - loaders.concat Array.wrap(child).flat_map { |assoc| - preloaders_on assoc, recs, scope + recs = loaders.flat_map(&:preloaded_records).uniq + loaders.concat Array.wrap(child).flat_map { |assoc| + preloaders_on assoc, recs, scope + } + loaders } end |