SQL does not use the equality comparison for null values, it uses 'IS
NULL' instead. Convenient, isn't it? ;)
Apparently Rails' magic does not go as far as to check if the NIL
value is one of the values in the array to generate the correct SQL
statement so I think you'll have to do it yourself and generate a
string such as:
conditions = "org is null or org in ('ABC', 'XYZ')"
This should be so easy to implement that I am not sure why it has not
already been done.
On Oct 4, 2:48 am, John Duu <[email protected]> wrote:
> Code snippet:
>
> conditions = {:org => ["ABC", "XYZ"]}
> Defect.count :conditions => conditions
>
> work as expected.
>
> This doesn't:
>
> conditions = {:org => ["ABC", "XYZ", nil]}
> Defect.count :conditions => conditions
>
> Get error: ActiveRecord::ActiveRecordError: Syntax error: Encountered
> "NULL" at line 1, column 87.: SELECT count(*) AS count_all FROM defects
> WHERE (defects.org IN ('ABC','XYZ',NULL))
>
> Any idea?
> --
> Posted viahttp://www.ruby-forum.com/.
--
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.