Ruby 我想知道 rails 怎麽區分大小寫查找

a1345774000 · August 17, 2021 · Last by a1345774000 replied at August 18, 2021 · 581 hits

我在查找的時候發現在查找的過程中 mysql 並不會對我查找的大寫或者小寫敏感,我想讓他在查找時候區分大小寫

1 Floor has deleted

like BINARY xx

account = Client.where(client_adress: email, del_flg: 0).first 我把我的代碼粘貼一下 client_adress: email 我想讓這個 client_adress 對大小寫敏感 大家有什麽好 的方法嗎我無法去更改數據庫

Reply to a1345774000

楼上不是给你回答了吗? 😅

Client.where("client_adress like binary('%xxx%')")

感謝兩位 我用的是 ruby on rails 框架好像沒有辦法這樣寫 我查找了 binary 的用法但我沒找到在控制器中的寫法 account = Client.where("client_adress link binary('%#{email}%'), del_flg: 0").first 現在是這麽寫的 可是沒有解決我的問題

where 要分开

Client.where("client_address like binary(?)", "%#{email}%").where(del_flg: 0)
Reply to zhengpd

感謝 這對我有用 我想請問一下您是怎麽知道這樣使用的 因爲我在谷歌查找用法的時候並沒有找到這樣的用法

Reply to a1345774000

看看 rails guide activerecord 的模块

You need to Sign in before reply, if you don't have an account, please Sign up first.