From d59f3a78a423064f53dadd9f55d05b5f7b2b240e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 7 May 2006 02:03:25 +0000 Subject: uniq preserves order. References [4325]. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4326 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/associations/association_collection.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index e705576120..428152eea0 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -109,7 +109,14 @@ module ActiveRecord end def uniq(collection = self) - collection.to_set.to_a + seen = Set.new + collection.inject([]) do |kept, record| + unless seen.include?(record.id) + kept << record + seen << record.id + end + kept + end end # Replace this collection with +other_array+ -- cgit v1.2.3