aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index de06931845..b2e8f32625 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -27,17 +27,18 @@ module ActiveRecord
def through_records_by_owner
Preloader.new(owners, through_reflection.name, through_scope).run
- Hash[owners.map do |owner|
- through_records = Array.wrap(owner.send(through_reflection.name))
+ owners.each_with_object({}) do |owner, h|
+ association = owner.association through_reflection.name
+ through_records = Array(association.reader)
# Dont cache the association - we would only be caching a subset
if (through_scope != through_reflection.klass.unscoped) ||
(reflection.options[:source_type] && through_reflection.collection?)
- owner.association(through_reflection.name).reset
+ association.reset
end
- [owner, through_records]
- end]
+ h[owner] = through_records
+ end
end
def through_scope