Rails 3 is not zero

I am trying to select all records that are not null from my table using the method

MyModel.where(:some_id => !nil) 

but it does not work, is there any other solution for this?

+6
source share
3 answers

Use a string, not a hash

 MyModel.where("some_id is not null") 
+7
source

You can do this using Arel syntax (which has a database independent bonus):

 MyModel.where(MyModel.arel_table['some_id'].not_eq(nil)) 
+12
source

You can use:

 MyModel.where("some_id IS NOT NULL") 
+1
source

Source: https://habr.com/ru/post/898520/


All Articles