From 761722287b894b12acb80713388cfbf7fe74eccf Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 23 Sep 2013 16:17:15 -0700 Subject: [PATCH] only do the should_reset test once --- .../associations/preloader/through_association.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index 09d1281ccc..7849810151 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -27,15 +27,15 @@ def associated_records_by_owner through_records = owners.map do |owner, h| association = owner.association through_reflection.name - x = [owner, Array(association.reader)] - - # Dont cache the association - we would only be caching a subset - association.reset if should_reset + [owner, Array(association.reader), association] + end - x + # Dont cache the association - we would only be caching a subset + if should_reset + through_records.each { |(_,_,assoc)| assoc.reset } end - middle_records = through_records.map { |(_,rec)| rec }.flatten + middle_records = through_records.map { |(_,rec,_)| rec }.flatten preloader = Preloader.new(middle_records, source_reflection.name, -- GitLab