Skip to content
Browse files

Fixed that calling Model.find([]) returns [] and doesn't throw an exc…

…eption #1379

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1471 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 361be5a commit a9fd639adf44cb17c6e3cd4f82d0025c8a7dcb64 @dhh dhh committed Jun 21, 2005
Showing with 7 additions and 0 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +1 −0 activerecord/lib/active_record/base.rb
  3. +4 −0 activerecord/test/finder_test.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that calling Model.find([]) returns [] and doesn't throw an exception #1379
+
* Fixed that adding a record to a has_and_belongs_to collection would always save it -- now it only saves if its a new record #1203 [Alisdair McDiarmid]
* Fixed saving of in-memory association structures to happen as a after_create/after_update callback instead of after_save -- that way you can add new associations in after_create/after_update callbacks without getting them saved twice
View
1 activerecord/lib/active_record/base.rb
@@ -333,6 +333,7 @@ def find(*args)
when :all
options[:include] ? find_with_associations(options) : find_by_sql(construct_finder_sql(options))
else
+ return args.first if args.first.kind_of?(Array) && args.first.empty?
expects_array = args.first.kind_of?(Array)
conditions = " AND #{sanitize_sql(options[:conditions])}" if options[:conditions]
View
4 activerecord/test/finder_test.rb
@@ -28,6 +28,10 @@ def test_find_by_ids
assert_equal(topics(:second).title, Topic.find([ 2 ]).first.title)
end
+ def test_find_an_empty_array
+ assert_equal [], Topic.find([])
+ end
+
def test_find_by_ids_missing_one
assert_raises(ActiveRecord::RecordNotFound) {
Topic.find(1, 2, 45)

0 comments on commit a9fd639

Please sign in to comment.
Something went wrong with that request. Please try again.