diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-27 15:20:54 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-27 15:20:54 -0700 |
commit | 89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e (patch) | |
tree | a04f0602c9bb6a5ad2d81052287cf87274cb772c /activerecord | |
parent | 594ce0f0a84f6de7719d59b55eee4b859efd6461 (diff) | |
download | rails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.tar.gz rails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.tar.bz2 rails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.zip |
cache association reset calculation
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index b2e8f32625..d35ffafe97 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 @@ module ActiveRecord def through_records_by_owner Preloader.new(owners, through_reflection.name, through_scope).run + should_reset = (through_scope != through_reflection.klass.unscoped) || + (reflection.options[:source_type] && through_reflection.collection?) + 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?) - association.reset - end + association.reset if should_reset h[owner] = through_records end |