From 57ed93ee66d99eb2cbcbcab3207fe9a8d293ce85 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 15 Dec 2004 11:55:43 +0000 Subject: Fixed that Base#find will return an array if given an array -- regardless of the number of elements #270 [Marten] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@164 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 899db1af10..f6233e5989 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -234,8 +234,10 @@ module ActiveRecord #:nodoc: # Person.find(1) # returns the object for ID = 1 # Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) # Person.find([7, 17]) # returns an array for objects with IDs in (7, 17) + # Person.find([1]) # returns an array for objects the object with ID = 1 # +RecordNotFound+ is raised if no record can be found. def find(*ids) + expects_array = ids.first.kind_of?(Array) ids = ids.flatten.compact.uniq if ids.length > 1 @@ -253,7 +255,7 @@ module ActiveRecord #:nodoc: sql << " AND #{type_condition}" unless descends_from_active_record? if record = connection.select_one(sql, "#{name} Find") - instantiate(record) + expects_array ? [instantiate(record)] : instantiate(record) else raise RecordNotFound, "Couldn't find #{name} with ID = #{id}" end -- cgit v1.2.3