aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader/through_association.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-18 07:07:23 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-18 07:07:23 +0900
commit5daf89f838abfd0c56d4a09bd352c987bc64ff9a (patch)
tree109b20abed26c97c84660bac1c75437793db5334 /activerecord/lib/active_record/associations/preloader/through_association.rb
parent45588fef7eef095d33beaf192b0b6a8c9c8af348 (diff)
downloadrails-5daf89f838abfd0c56d4a09bd352c987bc64ff9a.tar.gz
rails-5daf89f838abfd0c56d4a09bd352c987bc64ff9a.tar.bz2
rails-5daf89f838abfd0c56d4a09bd352c987bc64ff9a.zip
Don't pass `reflection_scope` to `preload_scope` if `reflection.scope` isn't given
Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17. If `reflection.scope` isn't given, `reflection_scope` is always empty scope. It is unnecessary to merge it.
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index 26bcdcbcc4..53e9c14823 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -28,6 +28,8 @@ module ActiveRecord
middle_records = through_records.flat_map(&:last)
+ reflection_scope = reflection_scope() if reflection.scope
+
preloaders = preloader.preload(middle_records,
source_reflection.name,
reflection_scope)
@@ -49,7 +51,7 @@ module ActiveRecord
}.compact
# Respect the order on `reflection_scope` if it exists, else use the natural order.
- if reflection_scope.values[:order].present?
+ if reflection_scope && !reflection_scope.order_values.empty?
@id_map ||= id_to_index_map @preloaded_records
rhs_records.sort_by { |rhs| @id_map[rhs] }
else