提交 a901433e 编写于 作者: A Aaron Patterson

return a list rather than hash

上级 8988f0b8
...@@ -14,15 +14,18 @@ def source_reflection ...@@ -14,15 +14,18 @@ def source_reflection
def associated_records_by_owner def associated_records_by_owner
through_records = through_records_by_owner through_records = through_records_by_owner
preloader = Preloader.new(through_records.values.flatten, middle_records = through_records.map { |rec| rec[1] }.flatten
preloader = Preloader.new(middle_records,
source_reflection.name, source_reflection.name,
reflection_scope) reflection_scope)
preloader.run preloader.run
through_records.each do |owner, records| through_records.each_with_object({}) { |(lhs,middles,assoc),h|
records.map! { |r| r.send(source_reflection.name) }.flatten! h[lhs] = middles.flat_map { |r|
records.compact! r.send(source_reflection.name)
end }.compact
}
end end
private private
...@@ -33,12 +36,15 @@ def through_records_by_owner ...@@ -33,12 +36,15 @@ def through_records_by_owner
should_reset = (through_scope != through_reflection.klass.unscoped) || should_reset = (through_scope != through_reflection.klass.unscoped) ||
(reflection.options[:source_type] && through_reflection.collection?) (reflection.options[:source_type] && through_reflection.collection?)
owners.each_with_object({}) do |owner, h| owners.map do |owner, h|
association = owner.association through_reflection.name association = owner.association through_reflection.name
h[owner] = Array(association.reader)
x = [owner, Array(association.reader), association]
# Dont cache the association - we would only be caching a subset # Dont cache the association - we would only be caching a subset
association.reset if should_reset association.reset if should_reset
x
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册