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?
You can check if an object is nil (null) by calling present? or blank? . @object. present? this will return false if the project is an empty string or nil .
Let's start out with “Nil” since it's the most common and easy-to-understand way of representing nothingness in Ruby. In terms of what it means, Nil is exactly the same thing as null in other languages. So, what is null? Null, as it exists in many languages, is a sort of value that represents “nothing”.
You can use exclude
instead of where
.
User.select(...).exclude(name: nil)
You can do this:
User.select(...).where('name IS NOT NULL')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With