Alex Rivera | Logout

Rails ActiveRecord conditions

Asked 2010-02-25T12:38:10.713
9

Is there a way to create a condition like this?

@products = Product.find(:all,
  :limit => 5,
  :conditions => { :products => { :locale => 'en', :id NOT '1' }, :tags => { :name => ['a','b']})

I would like to list all products not including product 1. Thx.

Edit
Report

1 Answer

9

Another way is to use the merge_conditions which turns the hash conditions into a string. Then you can add on whatever you want or call merge_conditions again with other options.

hash_conditions = {:category => 'computers'}
conditions = Product.merge_conditions(hash_conditions) + ' AND products.id NOT IN(1139) '
products = Product.find(:all, :conditions => conditions)
answered 2010-05-12T22:40:29.933

Your Answer