From a516fdefb6433993d7fcfda7b834fee1a2309d96 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 5 Sep 2017 01:35:27 +0900 Subject: Assigning `values` is only necessary when `reflection_scope.where_clause` is not empty Because `reflection_scope.values` will create extra new hash. --- .../lib/active_record/associations/preloader/through_association.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index f0a2e88c53..8aac00d910 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -81,12 +81,12 @@ module ActiveRecord def through_scope scope = through_reflection.klass.unscoped - values = reflection_scope.values if options[:source_type] scope.where! reflection.foreign_type => options[:source_type] elsif !reflection_scope.where_clause.empty? scope.where_clause = reflection_scope.where_clause + values = reflection_scope.values if includes = values[:includes] scope.includes!(source_reflection.name => includes) -- cgit v1.2.3