aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-25 10:40:50 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-25 10:40:50 -0700
commit57112fb7e7cb72584010b0957dfce91e0fc80a12 (patch)
tree5af59eeab4bb23d42d5dc56166bcff05bcada0c0 /activerecord/lib/active_record
parentbe91bb26408cadf3522eb8b8798f2118920cd1eb (diff)
downloadrails-57112fb7e7cb72584010b0957dfce91e0fc80a12.tar.gz
rails-57112fb7e7cb72584010b0957dfce91e0fc80a12.tar.bz2
rails-57112fb7e7cb72584010b0957dfce91e0fc80a12.zip
always populate the preloaded records instance variable so we can remove
the @associated_records_by_owner ivar
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/preloader/has_many_through.rb4
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb11
2 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/has_many_through.rb b/activerecord/lib/active_record/associations/preloader/has_many_through.rb
index 341e73f127..7b37b5942d 100644
--- a/activerecord/lib/active_record/associations/preloader/has_many_through.rb
+++ b/activerecord/lib/active_record/associations/preloader/has_many_through.rb
@@ -5,15 +5,13 @@ module ActiveRecord
include ThroughAssociation
def associated_records_by_owner(preloader)
- return @associated_records_by_owner if @associated_records_by_owner
-
records_by_owner = super
if reflection_scope.distinct_value
records_by_owner.each_value { |records| records.uniq! }
end
- @associated_records_by_owner = records_by_owner
+ records_by_owner
end
end
end
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index ec67a52885..08683d3250 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -4,7 +4,6 @@ module ActiveRecord
module ThroughAssociation #:nodoc:
def initialize(klass, owners, reflection, preload_scope)
super
- @associated_records_by_owner = nil
end
def through_reflection
@@ -15,10 +14,6 @@ module ActiveRecord
reflection.source_reflection
end
- def preloaded_records
- @associated_records_by_owner.values.flatten
- end
-
def associated_records_by_owner(preloader)
preloader.preload(owners,
through_reflection.name,
@@ -50,7 +45,7 @@ module ActiveRecord
}
end
- @associated_records_by_owner = through_records.each_with_object({}) { |(lhs,center),records_by_owner|
+ through_records.each_with_object({}) { |(lhs,center),records_by_owner|
pl_to_middle = center.group_by { |record| middle_to_pl[record] }
records_by_owner[lhs] = pl_to_middle.flat_map do |pl, middles|
@@ -64,7 +59,9 @@ module ActiveRecord
indexes[r] = i
i += 1
}
- rhs_records.sort_by { |rhs| record_index[rhs] }
+ records = rhs_records.sort_by { |rhs| record_index[rhs] }
+ @preloaded_records.concat rhs_records
+ records
end
}
end