0

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...

Flo Rahl
  • 1,044
  • 1
  • 16
  • 33

2 Answers2

1

Try these:

> Product.where("borrower_id !=?", nil)
> Product.where("borrower_id !=?", "")
rony36
  • 3,277
  • 1
  • 30
  • 42
1

Try

Product.where('borrower_id IS NOT NULL')
Soundar Rathinasamy
  • 6,658
  • 6
  • 29
  • 47