How do I test for non-null in Ruby::Sequel?
Asked Answered
P

3

16

I'm looking to do something like

User.select(...).where(:name != nil)

without writing something like

User.select(...).to_a.find_all {|user| user.name}

I can select for null values, but not for non-null. Is there a trick, or outside Sequel's domain?

Phlegm answered 26/5, 2014 at 21:38 Comment(0)
F
40

You can use exclude instead of where.

User.select(...).exclude(name: nil)
Farley answered 26/5, 2014 at 22:47 Comment(0)
C
9

The answer you seek is .where(Sequel.~(name: nil))

Read more here: https://github.com/jeremyevans/sequel/blob/master/doc/sql.rdoc

Charin answered 22/7, 2018 at 2:6 Comment(0)
Q
6

You can do this:

User.select(...).where('name IS NOT NULL')
Quigley answered 26/5, 2014 at 21:47 Comment(1)
This won't work outside of ActiveRecord. However, .where('name IS NOT NULL'.lit) would.Convertite

© 2022 - 2024 — McMap. All rights reserved.