aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-25 11:21:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-25 11:21:08 -0700
commitea87eb70b1e9776c50567db5c7718618766c9488 (patch)
tree0cbd1b3384cae83d9bccff840ac483f072af9670 /activerecord
parent71408911750ed7101f96bbe8a94ce06757052273 (diff)
downloadrails-ea87eb70b1e9776c50567db5c7718618766c9488.tar.gz
rails-ea87eb70b1e9776c50567db5c7718618766c9488.tar.bz2
rails-ea87eb70b1e9776c50567db5c7718618766c9488.zip
extract association resetting to a method
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index 08683d3250..17c46a4602 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -19,21 +19,15 @@ module ActiveRecord
through_reflection.name,
through_scope)
- should_reset = (through_scope != through_reflection.klass.unscoped) ||
- (reflection.options[:source_type] && through_reflection.collection?)
-
through_records = owners.map do |owner, h|
association = owner.association through_reflection.name
- [owner, Array(association.reader), association]
+ [owner, Array(association.reader)]
end
- # Dont cache the association - we would only be caching a subset
- if should_reset
- through_records.each { |(_,_,assoc)| assoc.reset }
- end
+ reset_association owners, through_reflection.name
- middle_records = through_records.map { |(_,rec,_)| rec }.flatten
+ middle_records = through_records.map { |(_,rec)| rec }.flatten
preloaders = preloader.preload(middle_records,
source_reflection.name,
@@ -68,6 +62,19 @@ module ActiveRecord
private
+ def reset_association(owners, association_name)
+ should_reset = (through_scope != through_reflection.klass.unscoped) ||
+ (reflection.options[:source_type] && through_reflection.collection?)
+
+ # Dont cache the association - we would only be caching a subset
+ if should_reset
+ owners.each { |owner|
+ owner.association(association_name).reset
+ }
+ end
+ end
+
+
def through_scope
scope = through_reflection.klass.unscoped