On Saturday, November 19, 2016 at 2:33:09 PM UTC-8, Andrew Burleson wrote:
>
> Hi Jeremy,
>
> Ran into another interesting thing:
>
> Assuming I have some attribute on users like "state", which might be nil.
>
> This query does just what I would expect:
>
> conversations = Conversation.eager_graph(:messages=>:user).where{{users[:
> state] => ['CA','TX','NY'] }}.all
>
users.state IN ('CA', 'TX', 'NY')
>
>
> And so does this one:
>
> conversations = Conversation.eager_graph(:messages=>:user).where{{users[:
> state] => nil }}.all
>
users.state IS NULL
>
>
> But I can't seem to combine the two:
>
> conversations = Conversation.eager_graph(:messages=>:user).where{{users[:
> state] => [nil, 'CA'] }}.all
>
>
users.state IN (NULL, 'CA')
> ^ In that case the ones with `nil` are missing from the query. I assume
> this is probably another syntax thing I'm missing, but I haven't been able
> to figure it out. Any way to combine "null" into a list of conditions?
>
Use the split_array_nil extension, or do:
where{Sequel.expr(users[:state] => 'CA') | {users[:state]=>nil} }
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.