【问题标题】:can we OR the scopes in scope builder?我们可以 OR 范围生成器中的范围吗?
【发布时间】:2011-08-01 05:46:00
【问题描述】:

我正在使用ryanb-scope-builder,我面临以下问题。

def self.search(options)
  scope_builder do |builder|
    builder.released.visible
    builder.cheap if options[:cheap]
  end
end

这会生成具有 :

的查询
builder.released.visible *AND* builder.cheap if options[:cheap]

而我希望范围像 OR'ed

builder.released.visible *OR* builder.cheap if options[:cheap]

是否有任何范围构建器 gem 可以解决这个问题? 谢谢

【问题讨论】:

标签: ruby-on-rails ruby rubygems named-scope


【解决方案1】:

我不知道这个范围生成器,但一般来说,OR 查询是使用 Arel 进行的。

看看这里:ActiveRecord OR query

此外,我怀疑这个宝石是否有用:

  • 范围本身很容易链接

  • 最后一次提交是在 2009 年

【讨论】:

  • 它是特定于 rails 3 的吗?还是2.x也可以用?
  • 知道了..可以独立使用版本。
猜你喜欢
  • 2015-09-20
  • 1970-01-01
  • 2021-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多