我们可以或范围生成器中的范围吗?
我正在使用 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]
而我希望对作用域进行“或”运算,例如
builder.released.visible *OR* builder.cheap if options[:cheap]
是否有任何作用域生成器 gem 可以解决此问题? 谢谢
I am using ryanb-scope-builder and I am facing following issue.
def self.search(options)
scope_builder do |builder|
builder.released.visible
builder.cheap if options[:cheap]
end
end
This generates query which has :
builder.released.visible *AND* builder.cheap if options[:cheap]
Whereas I want scope to be OR'ed like
builder.released.visible *OR* builder.cheap if options[:cheap]
Is there any scope builder gem which can solve this problem ??
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这个作用域生成器,但通常,OR 查询是使用 Arel 进行的。
看看这里: ActiveRecord OR 查询
此外,我怀疑这个宝石是否有用:
scopes本身很容易链接
最后一次提交是在 2009 年
I don't know this scope builder but generally, OR queries are made with Arel.
Have a look here: ActiveRecord OR query
Besides, I doubt this gem is that useful:
scopes are natively easy to chain
the last commit was in 2009