开发者

Exclude conditions in active relations, how?

开发者 https://www.devze.com 2023-03-08 10:23 出处:网络
I am seeking a way to do the opp开发者_如何学JAVAosite of : Model.where(:name => \'julian\') Something like :

I am seeking a way to do the opp开发者_如何学JAVAosite of :

Model.where(:name => 'julian')

Something like :

Model.where(:name => is_not('julian'))

I have found this post. But, find(:all, :conditions => {}) is now deprecated in rails 3 and moreover, I think a cleaner way to do this must exist.

Any suggestion ?


The simple answer is:

Model.where('models.name != ?', 'julian')

Unless, you want to get into building actual Arel conditions, in which case you would do something like:

Model.where(Model.arel_table[:name].not_eq('julian'))


Also, you can use meta_where gem: https://github.com/ernie/meta_where

0

精彩评论

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

关注公众号