The following code:
Page.find(:all, :conditions => { :author => ['Anonymous', nil]})
resutls in an SQL query like this:
[...] WHERE `author` IN ('Anonymous', NULL)
However, it does not return any pages with author = nil/NULL (using MySQL).
I fixed this by factroing out
active_record/base.rb in sanitize_sql_hash_for_conditions
"#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}"
into a new method, advanced_attribute_condition. It checks for an array-argument including nil and builds the SQL snippet accordingly. For example:
{ :author => ['Anonymous', nil] } #=> [...] WHERE (author = 'Anonymous' OR author IS NULL)
{ :type => ['a', 'b', nil] } #=> [...] WHERE (type IN ('a', 'b') OR type IS NULL)
This may also be handy when working with LEFT OUTER JOIN, as conditions affecting a associated table result in a RecordNotFound if no matching record can be found in it.