From 43a63f6d5ec2026dc7c610394aab37613181fff1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Oct 2013 13:23:03 -0700 Subject: the preloader for the RHS has all the preloaded records, so ask it --- .../lib/active_record/associations/preloader/through_association.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (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 63d4253e6a..edce1d80c5 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -29,6 +29,8 @@ module ActiveRecord source_reflection.name, reflection_scope) + @preloaded_records.concat preloaders.flat_map(&:preloaded_records) + middle_to_pl = preloaders.each_with_object({}) do |pl,h| pl.owners.each { |middle| h[middle] = pl @@ -53,9 +55,7 @@ module ActiveRecord }.compact record_index = pl_indexes[pl] - records = rhs_records.sort_by { |rhs| record_index[rhs] } - @preloaded_records.concat rhs_records - records + rhs_records.sort_by { |rhs| record_index[rhs] } end } end -- cgit v1.2.3