14

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?

Eric
  • 2,115
  • 2
  • 20
  • 29

3 Answers3

38

You can use exclude instead of where.

User.select(...).exclude(name: nil)
Alex Peachey
  • 4,606
  • 22
  • 18
9

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

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

Mason Cloud
  • 1,266
  • 1
  • 15
  • 20
6

You can do this:

User.select(...).where('name IS NOT NULL')
zishe
  • 10,665
  • 12
  • 64
  • 103