I second this. I often want to do queries like (field is not null and field
<> ''). But when using an ORM, I'd prefer to generate such queries with
statements like:
ds.exclude(field: [nil, ''])
instead of
ds.exclude(field: nil).exclude(field: '')
I just think this feels more natural than just converting to "field NOT IN
(NULL, '')".
While the SQL IN behavior makes sense given that NULL == NULL is the
unknown state in Sql, I'd really prefer to use the Ruby behavior when doing
ORM (ie, nil == nil is true).
Maybe you could provide some "Sequel.smart_nil_handling_on_in_list = true"
option?
Cheers,
Rodrigo.
Em quarta-feira, 8 de junho de 2011 13h20min43s UTC-3, Michael Lang
escreveu:
>
> > uninsured_codes = nil
> => nil
> > DB[:insurances].filter(:code => uninsured_codes).sql
> => "SELECT * FROM `insurances` WHERE (`code` IS NULL)"
>
> Good!
>
> > uninsured_codes = ['', 'NO INS', 'NO INS HS', 'HMLS-NOIN', 'NDA']
> => ["", "NO INS", "NO INS HS", "HMLS-NOIN", "NDA"]
> > DB[:insurances].filter(:code => uninsured_codes).sql
> => "SELECT * FROM `insurances` WHERE (`code` IN ('', 'NO INS', 'NO INS
> HS', 'HMLS-NOIN', 'NDA'))"
>
> Good!
>
> > uninsured_codes = [nil, '', 'NO INS', 'NO INS HS', 'HMLS-NOIN', 'NDA']
> => [nil, "", "NO INS", "NO INS HS", "HMLS-NOIN", "NDA"]
> > DB[:insurances].filter(:code => uninsured_codes).sql
> => "SELECT * FROM `insurances` WHERE (`code` IN (NULL, '', 'NO INS',
> 'NO INS HS', 'HMLS-NOIN', 'NDA'))"
>
> Above doesn't work in mysql. The record with NULL is not returned.
> Need to see:
> => "SELECT * FROM `insurances` WHERE ((`code` IN ('', 'NO INS', 'NO
> INS HS', 'HMLS-NOIN', 'NDA')) OR (`code` IS NULL))"
>
> With the above query, the NULL record is returned along with the others.
>
> Can Sequel be extended to do "OR <field> IS NULL" when an array with
> legit values as well as nil is passed?
>
> Michael
>
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/rr5HL-S-9ikJ.
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/sequel-talk?hl=en.