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

时间:2021-07-15 11:15:18

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 })

1 个解决方案

#1


2  

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查询

#1


2  

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查询