> Found a bug/workaround/fix. Not sure which.
>
> conditions = {:org => ["ABC", "XYZ", "NULL"]}
> Defect.count :conditions => conditions

Just ran a quick test on a table of mine with 7 records (6 with the
same value in the column being searched and one record with a value of
null in it) and your code above does not work for me (using MSSQL). It
just doesn't produce an error but the record with a NULL value is not
counted. The only way I found to count the NULL, *and only the null*,
with the syntax you've been using is this:

condition = {:my_column => nil}

> Don't know what to do if the org name really is "NULL".

As far as I can see you will need to either modify your condition
value or run 2 separate counts, one for the nil ones and another one
for the other values. This code should help if you want to go with the
first option, I think:

YourModel.count :conditions => "your_column is null or your_column in
('#{your_values.join('\',\'')}')"

This assumes 'your_values' is an array. The code above will probably
not work, however, if 'your_values' is empty as the content of your
parenthesis will end up looking like this:
('')

Then the query would select (if they exist) records with an empty
value in 'your_column', which is something you might want to consider
as well since 'your_column' contains strings. So something like this
should work:

YourModel.count :conditions => "your_column is null or your_column =
'' or your_column in ('#{your_values.join('\',\'')}')"

If there is a better way I'd like to know.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to