亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 630 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號