I did a search and found ticket #7599 which made it possible to write e.g.
Person.find(:first, :conditions => "")
without running into a SQL error. It seems, however, that this error crops back up with a nested with_scope:
Person.with_scope :find => { :conditions => "" } do
Person.with_scope :find => { :conditions => "" } do
Person.find(:first)
end
end
The exact error I got was:
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND ( )) LIMIT 1' at line 1: SELECT * FROM `products` WHERE (( ) AND ( )) LIMIT 1
I did some snooping about in the Rails source and I think the culprit may be, unsurprisingly, ActiveRecord::Base.with_scope itself, specifically this passage:
if key == :conditions && merge
hash[method][key] = [params[key], hash[method][key]].collect{ |sql| "( %s )" % sanitize_sql(sql) }.join(" AND ")
elsif...
I believe that making sure that sql is not blank before assigning to hash[method][key] will fix this bug, or it might possibly be as simple as writing .compact before the join, or perhaps a combination of both.
I'll do some more testing later today, but this is just a heads up.