【发布时间】:2020-04-30 12:04:23
【问题描述】:
我相信这对于知道自己在做什么的人来说会很简单。我想将此语句写为一个范围 - 我宁愿使用 Arel 格式,但无法计算出 AND 内的 OR
select * from contacts where contact_type in (1,2) and
((contactable_type = 'Developer' and contactable_id = 10) or (contactable_type = 'Development' and contactable_id = 24))
所以开始我的范围 - 第一点很简单
scope :of_type,
lambda { |types|
where(contact_type: types)
}
但这是我无法获得的带有嵌套 OR 的 AND。我显然会发送我需要的身份证件
scope :of_type,
lambda { |types, developer_id, development_id |
where(contact_type: types) .. .
}
【问题讨论】:
-
你的 Rails 版本是什么?
标签: ruby-on-rails ruby arel