aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-06-21 16:36:18 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-06-21 16:36:18 +0000
commita9fd639adf44cb17c6e3cd4f82d0025c8a7dcb64 (patch)
tree258a958618569d1653efaba1d5249e2cec3c8fbe /activerecord
parent361be5a7dd1d70e55d6b003b987794e94b2f9c1e (diff)
downloadrails-a9fd639adf44cb17c6e3cd4f82d0025c8a7dcb64.tar.gz
rails-a9fd639adf44cb17c6e3cd4f82d0025c8a7dcb64.tar.bz2
rails-a9fd639adf44cb17c6e3cd4f82d0025c8a7dcb64.zip
Fixed that calling Model.find([]) returns [] and doesn't throw an exception #1379
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1471 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb1
-rw-r--r--activerecord/test/finder_test.rb4
3 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e07265b3ac..f2bc01bc06 100644
--- a/activerecord/CHANGELOG
+++ b/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
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 0587b0bab8..2d4501e678 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -333,6 +333,7 @@ module ActiveRecord #:nodoc:
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]
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index 307fd0934c..06c5229433 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -28,6 +28,10 @@ class FinderTest < Test::Unit::TestCase
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)