diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-05-04 13:58:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-04 13:58:27 -0700 |
commit | 0ba7c17e9d46938dda19c8ff9281522b243bbf54 (patch) | |
tree | 0ce6d3e329dd712fcc50b2c77d5126f76b5c5633 /activerecord/lib/active_record | |
parent | 7ff5ccae94ce2aff76b5f8a31a28e305a047d642 (diff) | |
parent | 38a7d189d285a5954946780fdd7fc42e824beb99 (diff) | |
download | rails-0ba7c17e9d46938dda19c8ff9281522b243bbf54.tar.gz rails-0ba7c17e9d46938dda19c8ff9281522b243bbf54.tar.bz2 rails-0ba7c17e9d46938dda19c8ff9281522b243bbf54.zip |
Merge pull request #28983 from kamipo/remove_useless_target_records_from_association
Remove useless `target_records_from_association`
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index 9d44a02021..d53d3f777b 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -16,15 +16,13 @@ module ActiveRecord through_scope) through_records = owners.map do |owner| - association = owner.association through_reflection.name - - center = target_records_from_association(association) + center = owner.association(through_reflection.name).target [owner, Array(center)] end reset_association owners, through_reflection.name - middle_records = through_records.flat_map { |(_, rec)| rec } + middle_records = through_records.flat_map(&:last) preloaders = preloader.preload(middle_records, source_reflection.name, @@ -43,9 +41,7 @@ module ActiveRecord records_by_owner[lhs] = pl_to_middle.flat_map do |pl, middles| rhs_records = middles.flat_map { |r| - association = r.association source_reflection.name - - target_records_from_association(association) + r.association(source_reflection.name).target }.compact # Respect the order on `reflection_scope` if it exists, else use the natural order. @@ -98,10 +94,6 @@ module ActiveRecord scope end - - def target_records_from_association(association) - association.loaded? ? association.target : association.reader - end end end end |