加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails ActiveRecord条件

发布时间:2020-12-16 22:27:52 所属栏目:百科 来源:网络整理
导读:有没有办法创建这样的条件? @products = Product.find(:all,:limit = 5,:conditions = { :products = { :locale = 'en',:id NOT '1' },:tags = { :name = ['a','b']}) 我想列出所有不包括产品的产品1. 谢谢. 解决方法 轨道3 使用squeel宝石. Product.where(
有没有办法创建这样的条件?
@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']}
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读