aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-14 13:27:52 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-14 13:27:52 -0700
commit03c98bddfd22d8df9daa0ea74f04f1ee72cddf89 (patch)
tree85ec3d44516882e993fb902e8f1d6bd9e5532cfb
parent43a63f6d5ec2026dc7c610394aab37613181fff1 (diff)
downloadrails-03c98bddfd22d8df9daa0ea74f04f1ee72cddf89.tar.gz
rails-03c98bddfd22d8df9daa0ea74f04f1ee72cddf89.tar.bz2
rails-03c98bddfd22d8df9daa0ea74f04f1ee72cddf89.zip
simplify populating the ordering hash
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb15
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index edce1d80c5..21f2fb7cc7 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -29,7 +29,7 @@ module ActiveRecord
source_reflection.name,
reflection_scope)
- @preloaded_records.concat preloaders.flat_map(&:preloaded_records)
+ @preloaded_records = preloaders.flat_map(&:preloaded_records)
middle_to_pl = preloaders.each_with_object({}) do |pl,h|
pl.owners.each { |middle|
@@ -37,13 +37,9 @@ module ActiveRecord
}
end
- pl_indexes = preloaders.each_with_object({}) do |pl,hash|
- i = 0
- loaded_records = pl.preloaded_records
- hash[pl] = loaded_records.each_with_object({}) { |r,indexes|
- indexes[r] = i
- i += 1
- }
+ record_offset = {}
+ @preloaded_records.each_with_index do |record,i|
+ record_offset[record] = i
end
through_records.each_with_object({}) { |(lhs,center),records_by_owner|
@@ -54,8 +50,7 @@ module ActiveRecord
r.send(source_reflection.name)
}.compact
- record_index = pl_indexes[pl]
- rhs_records.sort_by { |rhs| record_index[rhs] }
+ rhs_records.sort_by { |rhs| record_offset[rhs] }
end
}
end