2

I am seeking a way to do the opposite 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 ?

Hartator
  • 5,029
  • 4
  • 43
  • 73
  • Are you sure that `find(:all, :conditions => {})` is deprecated in rails 3? I'm using 3.0.7 and don't get any deprecation warnings when i use it. – Max Williams May 25 '11 at 10:06
  • According to [this article](http://m.onkey.org/active-record-query-interface) passing `:conditions` to `find` as well as `find(:all)` is deprecated in Rails 3 and will be removed in Rails 3.2. – aNoble May 25 '11 at 16:51

2 Answers2

9

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'))
aNoble
  • 7,033
  • 2
  • 37
  • 33
0

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

Ptico
  • 151
  • 1
  • 4