1

I have User model embeds_one :profile and Profile model has name. I need to run LIKE query on profile name. I tried below as suggested here

User.where("profile.name" => "/.*Senthil.*/")

But above solution not working. I tried lot of stock overflow answers , but no luck. Any help will be highly appreciated.

Screenshot : I am very sure , there is matching record.

enter image description here

Community
  • 1
  • 1
Senthil
  • 946
  • 1
  • 14
  • 34

2 Answers2

6

This finds all people with the name senthil (first OR last).

User.where("profile.name" => /.*senthil.*/i )

Here i used to make the query case insensitive.

Sharvy Ahmed
  • 7,247
  • 1
  • 33
  • 46
1

I think you mean to remove the quotes, otherwise the engine will try to match the string exactly, instead of as regex

edit: The correct regexp would be

User.where("profile.name" => /.*Senthil.*/)

jtmarmon
  • 5,727
  • 7
  • 28
  • 45