Permalink
Browse files

Fixed that Base.find :all, :conditions => [ "id IN (?)", collection ]…

… would fail if collection was empty [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4390 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 24a5a80 commit 9fcc0654c37772a3d6884c5d6f7099a39fe88f73 @dhh dhh committed Jun 1, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that Base.find :all, :conditions => [ "id IN (?)", collection ] would fail if collection was empty [DHH]
+
* Add a list of regexes assert_queries skips in the ActiveRecord test suite. [Rick]
* Fix the has_and_belongs_to_many #create doesn't populate the join for new records. Closes #3692 [josh@hasmanythrough.com]
@@ -1309,7 +1309,11 @@ def replace_named_bind_variables(statement, bind_vars) #:nodoc:
def quote_bound_value(value) #:nodoc:
if (value.respond_to?(:map) && !value.is_a?(String))
- value.map { |v| connection.quote(v) }.join(',')
+ if value.empty?
+ "null"
+ else
+ value.map { |v| connection.quote(v) }.join(',')
+ end
else
connection.quote(value)
end
@@ -933,10 +933,10 @@ def test_column_name_properly_quoted
end
def test_quoting_arrays
- replies = Reply.find(:all, :conditions => [ "id IN (?)", topics(:first).replies.to_s(:db) ])
+ replies = Reply.find(:all, :conditions => [ "id IN (?)", topics(:first).replies.collect(&:id) ])
assert_equal topics(:first).replies.size, replies.size
- replies = Reply.find(:all, :conditions => [ "id IN (?)", [].to_s(:db) ])
+ replies = Reply.find(:all, :conditions => [ "id IN (?)", [] ])
assert_equal 0, replies.size
end
View
@@ -2,7 +2,7 @@
* Added Array#to_s(:db) that'll produce a comma-separated list of ids [DHH]. Example:
- Purchase.find(:all, :conditions => [ "product_id IN (?)", shop.products.to_s(:db) ])
+ Purchase.find(:all, :conditions => "product_id IN (#{shops.products.to_s(:db)})"
* Normalize classify's argument to a String so that it plays nice with Symbols. [Marcel Molina Jr.]
@@ -35,7 +35,7 @@ def to_formatted_s(format = :default)
case format
when :db
if respond_to?(:empty?) && self.empty?
- "0"
+ "null"
else
collect { |element| element.id }.join(",")
end

0 comments on commit 9fcc065

Please sign in to comment.