diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 20:11:45 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 20:11:45 -0700 |
commit | a901433ee3bd318fd6c87b939ddabe0925830bc9 (patch) | |
tree | 383fc3b7e3c018902cc0194e427bd381e911fb9a /activerecord/lib | |
parent | 8988f0b8beec83a8ead61da93818270e82e76694 (diff) | |
download | rails-a901433ee3bd318fd6c87b939ddabe0925830bc9.tar.gz rails-a901433ee3bd318fd6c87b939ddabe0925830bc9.tar.bz2 rails-a901433ee3bd318fd6c87b939ddabe0925830bc9.zip |
return a list rather than hash
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index 3001177d15..d6972bd2be 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -14,15 +14,18 @@ module ActiveRecord def associated_records_by_owner through_records = through_records_by_owner - preloader = Preloader.new(through_records.values.flatten, + middle_records = through_records.map { |rec| rec[1] }.flatten + + preloader = Preloader.new(middle_records, source_reflection.name, reflection_scope) preloader.run - through_records.each do |owner, records| - records.map! { |r| r.send(source_reflection.name) }.flatten! - records.compact! - end + through_records.each_with_object({}) { |(lhs,middles,assoc),h| + h[lhs] = middles.flat_map { |r| + r.send(source_reflection.name) + }.compact + } end private @@ -33,12 +36,15 @@ module ActiveRecord should_reset = (through_scope != through_reflection.klass.unscoped) || (reflection.options[:source_type] && through_reflection.collection?) - owners.each_with_object({}) do |owner, h| + owners.map do |owner, h| association = owner.association through_reflection.name - h[owner] = Array(association.reader) + + x = [owner, Array(association.reader), association] # Dont cache the association - we would only be caching a subset association.reset if should_reset + + x end end |