From 5daf89f838abfd0c56d4a09bd352c987bc64ff9a Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 18 Sep 2017 07:07:23 +0900 Subject: 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. --- .../lib/active_record/associations/preloader/through_association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3