1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Avoid iterating over records hash when not necessary

If the reflection scope is not flagged with distinct value, there is no
need to iterate over the records, so we avoid that by doing the check
before iterating rather than inside the iteration block.
This commit is contained in:
Carlos Antonio da Silva 2013-04-07 12:13:47 -03:00
parent 1eee48144b
commit 492e6b57d4

View file

@ -5,9 +5,13 @@ module ActiveRecord
include ThroughAssociation
def associated_records_by_owner
super.each_value do |records|
records.uniq! if reflection_scope.distinct_value
records_by_owner = super
if reflection_scope.distinct_value
records_by_owner.each_value { |records| records.uniq! }
end
records_by_owner
end
end
end