aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-08-27 15:20:54 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-08-27 15:20:54 -0700
commit89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e (patch)
treea04f0602c9bb6a5ad2d81052287cf87274cb772c /activerecord/lib
parent594ce0f0a84f6de7719d59b55eee4b859efd6461 (diff)
downloadrails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.tar.gz
rails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.tar.bz2
rails-89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e.zip
cache association reset calculation
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb8
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