diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/has_many_through.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/has_many_through.rb | 10 |
1 files changed, 7 insertions, 3 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 9a662d3f53..7b37b5942d 100644 --- a/activerecord/lib/active_record/associations/preloader/has_many_through.rb +++ b/activerecord/lib/active_record/associations/preloader/has_many_through.rb @@ -4,10 +4,14 @@ module ActiveRecord class HasManyThrough < CollectionAssociation #:nodoc: include ThroughAssociation - def associated_records_by_owner - super.each do |owner, records| - records.uniq! if reflection_scope.uniq_value + def associated_records_by_owner(preloader) + records_by_owner = super + + if reflection_scope.distinct_value + records_by_owner.each_value { |records| records.uniq! } end + + records_by_owner end end end |