Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 not nil

I'm trying to select all records that are not null from my table using where method

MyModel.where(:some_id => !nil) 

but it doesn't work, is there any other solution to do this?

like image 251
Maki Avatar asked Oct 03 '11 13:10

Maki


2 Answers

You can do it using the Arel syntax (which has the bonus of being database independent):

MyModel.where(MyModel.arel_table['some_id'].not_eq(nil))
like image 113
Benoit Garret Avatar answered Sep 29 '22 08:09

Benoit Garret


Use a string rather than a hash

MyModel.where("some_id is not null")
like image 29
Rob Di Marco Avatar answered Sep 29 '22 07:09

Rob Di Marco