mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor association_collection uniq method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
2da809da37
commit
f6de806537
1 changed files with 3 additions and 4 deletions
|
@ -338,13 +338,12 @@ module ActiveRecord
|
|||
|
||||
def uniq(collection = self)
|
||||
seen = Set.new
|
||||
collection.inject([]) do |kept, record|
|
||||
collection.map do |record|
|
||||
unless seen.include?(record.id)
|
||||
kept << record
|
||||
seen << record.id
|
||||
record
|
||||
end
|
||||
kept
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
# Replace this collection with +other_array+
|
||||
|
|
Loading…
Reference in a new issue