postgresql 如何在 Ruby on Rails 中使用 LIKE 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16200771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:53:21  来源:igfitidea点击:

How to use LIKE query in Ruby on Rails

mysqlruby-on-railspostgresql

提问by bzupnick

LIKE query in mysql, queries the database and disregards case. For example:

mysql中的LIKE查询,查询数据库,不区分大小写。例如:

"bzupnick" = "Bzupnick" #  false
"bzupnick" LIKE "Bzupnick" # true

So how does one do a LIKE query in Ruby on Rails.

那么如何在 Ruby on Rails 中执行 LIKE 查询呢?

Here's an example query:

这是一个示例查询:

@results = User.joins(:jobs).where(:jobs => { :job_name => job }, :users => { :zip => zip })

回答by Aditya Kapoor

try this..

试试这个..

User.joins(:job).where("job_name like ? and name like ?","%Dummy%", "%Bzupnick")

You can also verfify the SQL query by putting to_sql at the end of the above statement

您还可以通过将 to_sql 放在上述语句的末尾来验证 SQL 查询