Robert Walker wrote:
> John Duu wrote:
>> conditions = {:org => ["ABC", "XYZ", "NULL"]}
>> Defect.count :conditions => conditions
>>
>> Don't know what to do if the org name really is "NULL".
>
> The string "NULL" is not the same as a NULL value in a field. I doubt
> what you're showing here will generate the proper SQL as shown earlier
> by pepe:
>
> pepe wrote:
>> conditions = "org is null or org in ('ABC', 'XYZ')"
>
> You need to actually check the generated SQL in your development log to
> make sure it looks something like the above.
Seem to be picking up nil correctly.
code snippet:
conditions = {:org => ["NULL"]}
defects = Defect.first :conditions => conditions
puts defects.inspect
output:
Defect Load (15.0ms) SELECT * FROM defects WHERE (defects.org IN
('NULL')) FETCH FIRST 1 ROWS ONLY
#<Defect id: 1, org: nil, created_at: "2010-10-04 00:14:20", updated_at:
"2010-10-04 00:14:20>
I'm using JRuby 1.5.1 with JavaDB. Haven't tried with mysql or other db.
Not too familiar with raw sql, so don't know if WHERE (defects.org IN
('NULL')) is equivalent to org IS NULL or if this syntax is a JavaDB
specific.
--
Posted via http://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.