aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-05-04 20:33:15 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-05-04 20:33:15 +0900
commit38a7d189d285a5954946780fdd7fc42e824beb99 (patch)
tree2385c7c71bdd44e0ca788e7fa40a246f66d72392 /activerecord/lib/active_record
parentaed797eb57fe712d77c327143fafcfce56863d05 (diff)
downloadrails-38a7d189d285a5954946780fdd7fc42e824beb99.tar.gz
rails-38a7d189d285a5954946780fdd7fc42e824beb99.tar.bz2
rails-38a7d189d285a5954946780fdd7fc42e824beb99.zip
Remove useless `target_records_from_association`
Since through association is always loaded by `preloader.preload`.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb14
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