有没有办法创建这样的条件?
@products = Product.find(:all,:limit => 5,:conditions => { :products => { :locale => 'en',:id NOT '1' },:tags => { :name => ['a','b']})
我想列出所有不包括产品的产品1.
谢谢.
解决方法
轨道3
使用squeel宝石.
Product.where( :products => { :locale => 'en',:id.not_in => '1' },'b']} ).limit(5)
轨道2
为此使用AR Extensions.它支持以下条件修饰符:
* _lt => less than * _gt => greater than * _lte => less than or equal to * _gte => greater than or equal to * _ne => not equal to * _not => not equal to
现在可以重写您的查询如下:
@products = Product.find(:all,:joins => [:tags],:conditions => { :locale => 'en',:id_not => '1','b']} )