Flo Rahl
Flo Rahl

Reputation: 1054

"Where" method with "not nil" checking

How can I check if my variable is not nil when I use the "where" method ?

I tried these on a Product model that has a borrower_id field, but it didn't worked properly :

> Product.where("borrower_id.nil?")
> Product.where("borrower_id != nil")
> Product.where("borrower_id == !nil")

The only way I found was this one :

> Product.where("borrower_id > 0")

But it doesn't seem very clean...

Upvotes: 0

Views: 129

Answers (2)

Soundar Rathinasamy
Soundar Rathinasamy

Reputation: 6728

Try

Product.where('borrower_id IS NOT NULL')

Upvotes: 1

rony36
rony36

Reputation: 3339

Try these:

> Product.where("borrower_id !=?", nil)
> Product.where("borrower_id !=?", "")

Upvotes: 1

Related Questions