diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 20:14:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 20:14:52 -0700 |
commit | 99568a7a2d17f236dee0d41aa69a637f698b5275 (patch) | |
tree | 32d1b799df6b1d8454091556ee2ca29b8b1f4a44 /activerecord/lib | |
parent | a901433ee3bd318fd6c87b939ddabe0925830bc9 (diff) | |
download | rails-99568a7a2d17f236dee0d41aa69a637f698b5275.tar.gz rails-99568a7a2d17f236dee0d41aa69a637f698b5275.tar.bz2 rails-99568a7a2d17f236dee0d41aa69a637f698b5275.zip |
combine methods so we can reuse preloaders
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index d6972bd2be..eaceb6c3d9 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -12,7 +12,24 @@ module ActiveRecord end def associated_records_by_owner - through_records = through_records_by_owner + left_loader = Preloader.new(owners, + through_reflection.name, + through_scope) + left_loader.run + + should_reset = (through_scope != through_reflection.klass.unscoped) || + (reflection.options[:source_type] && through_reflection.collection?) + + through_records = owners.map do |owner, h| + association = owner.association through_reflection.name + + x = [owner, Array(association.reader), association] + + # Dont cache the association - we would only be caching a subset + association.reset if should_reset + + x + end middle_records = through_records.map { |rec| rec[1] }.flatten @@ -30,24 +47,6 @@ module ActiveRecord private - def through_records_by_owner - Preloader.new(owners, through_reflection.name, through_scope).run - - should_reset = (through_scope != through_reflection.klass.unscoped) || - (reflection.options[:source_type] && through_reflection.collection?) - - owners.map do |owner, h| - association = owner.association through_reflection.name - - 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 - def through_scope scope = through_reflection.klass.unscoped |