ruby-on-rails – Rails ActiveRecord条件

有没有办法创建这样的条件?
@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']}
)

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...