ruby-on-rails – Rails ActiveRecord条件

前端之家收集整理的这篇文章主要介绍了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']}
)
原文链接:https://www.f2er.com/ruby/266020.html

猜你在找的Ruby相关文章