为了账号安全,请及时绑定邮箱和手机立即绑定

ActiveRecord或查询哈希符号

ActiveRecord或查询哈希符号

慕尼黑的夜晚无繁华 2019-11-28 10:44:56
我知道有3种主要符号为whereActiveRecord方法提供参数:纯弦数组杂凑指定and的where方法是直截了当:# Pure String notationPerson.where("name = 'Neil' AND age = 27")# Array notationPerson.where(["name = ? AND age = ?", 'Neil', 27])# Hash notationPerson.where({name: "Neil", age: 27})指定or相同的where方法让我很困惑哈希语法。可能吗?# Pure String notationPerson.where("name = 'Neil' OR age = 27")# Array notationPerson.where(["name = ? OR age = ?", 'Neil', 27])# Hash notation DOESN'T WORKPerson.where({name: "Neil" OR age: 27})
查看完整描述

2 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

正如potashin所说,您可以使用另一个实现此功能的第三方插件。我使用Squeel的时间很长,为此和其他功能(例如复杂的子查询或联接)工作得很好。


该查询使用squeel:


@people= Person.where{(name == 'Neil') | (age = 27)}


查看完整回答
反对 回复 2019-11-28
  • 2 回答
  • 0 关注
  • 536 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信