Rails ActiveRecord conditions

后端 未结 4 1264
误落风尘
误落风尘 2020-12-15 11:26

Is there a way to create a condition like this?

@products = Product.find(:all,
  :limit => 5,
  :conditions => { :products => { :locale => \'en\'         


        
4条回答
  •  误落风尘
    2020-12-15 12:14

    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)
    

提交回复
热议问题