12

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
  • 1,832
  • 2
  • 17
  • 27

3 Answers3

28

You can use exclude instead of where.

User.select(...).exclude(name: nil)
Alex Peachey
  • 4,306
  • 19
  • 18
5

You can do this:

User.select(...).where('name IS NOT NULL')
zishe
  • 10,055
  • 12
  • 60
  • 101
2

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,130
  • 1
  • 11
  • 18