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
精彩评论