From f6de806537d60e94183f26cd6a16da426e84911e Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 11:22:49 -0300 Subject: Refactor association_collection uniq method. Signed-off-by: Santiago Pastorino --- .../lib/active_record/associations/association_collection.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 1221a56bbc..91e0a9f2f8 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -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+ -- cgit v1.2.3