Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude conditions in active relations, how?

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 ?

like image 673
Hartator Avatar asked Nov 20 '25 08:11

Hartator


1 Answers

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'))
like image 69
aNoble Avatar answered Nov 21 '25 23:11

aNoble



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!