Reputation: 105
I'm having an Active Record in my rails application in which each row of the table MyTable contains:
Now I want to query my database to pull all the records in which a particular queryString
is present in strinArr
of that record.
I know we can do MyTable.where(xyz:someXYZ)
to pull all the records with xyz
value as someXYZ
?
But how can I do this query?
Upvotes: 2
Views: 160
Reputation: 57
You can use the sql like clause
MyTable.where("stringArr LIKE :keywords",{keywords: '%querystring%'})
Upvotes: 1
Reputation: 1535
To fetch all record, which contains queryString
in an array of records, you can do -
MyTable.where("column_name LIKE ?","'%queryString%'"})
This will do exact query string search means return all data, which column_name
contains queryString
.
Upvotes: 1