On Jun 8, 9:20 am, Michael Lang <[email protected]> wrote:
> > 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?

Such a change is easy to make, but I think it is a bad idea.  NULL =
NULL is not true in SQL (it is NULL).  Here's a simple example:

  artists = []
  artists << Artist.load(:id=>1)
  artists << Artist.new
  artist_ids = artists.map{|a| a.id} # [1, nil]
  albums_for_artists = Album.filter(:artist_id=>artist_ids).all

With your idea, albums_for_artists will be all albums for artist 1 and
all albums that don't have an artist.  That's obviously not what is
desired.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-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/sequel-talk?hl=en.

Reply via email to