diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-27 15:14:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-27 15:14:48 -0700 |
commit | 594ce0f0a84f6de7719d59b55eee4b859efd6461 (patch) | |
tree | 7bc049bac83ea0edae6f95f6084523744b826c66 /activerecord/lib/active_record | |
parent | 169c2141fc4b37788582fe02908f696a56d70a7b (diff) | |
download | rails-594ce0f0a84f6de7719d59b55eee4b859efd6461.tar.gz rails-594ce0f0a84f6de7719d59b55eee4b859efd6461.tar.bz2 rails-594ce0f0a84f6de7719d59b55eee4b859efd6461.zip |
query the association rather than send the method for the association name
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 11 |
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 |