Permalink
Browse files

always populate the preloaded records instance variable so we can remove

the @associated_records_by_owner ivar
  • Loading branch information...
1 parent be91bb2 commit 57112fb7e7cb72584010b0957dfce91e0fc80a12 @tenderlove tenderlove committed Sep 25, 2013
@@ -5,15 +5,13 @@ class HasManyThrough < CollectionAssociation #:nodoc:
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
@@ -4,7 +4,6 @@ class Preloader
module ThroughAssociation #:nodoc:
def initialize(klass, owners, reflection, preload_scope)
super
- @associated_records_by_owner = nil
end
def through_reflection
@@ -15,10 +14,6 @@ def source_reflection
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 @@ def associated_records_by_owner(preloader)
}
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 @@ def associated_records_by_owner(preloader)
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

0 comments on commit 57112fb

Please sign in to comment.