开发者

rails 3 not nil

开发者 https://www.devze.com 2023-04-10 12:49 出处:网络
I\'m trying to select all records that are not null from m开发者_Go百科y table using where method

I'm trying to select all records that are not null from m开发者_Go百科y table using where method

MyModel.where(:some_id => !nil) 

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


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


Use a string rather than a hash

MyModel.where("some_id is not null")


You can use:

MyModel.where("some_id IS NOT NULL") 
0

精彩评论

暂无评论...
验证码 换一张
取 消