Thomas
Thomas

Reputation: 2952

How to cast ID field to text in squeel query

I essentially want to perform a LIKE query on a PostgreSQL primary id column for a query generated using Squeel and I don't think Squeel is understanding the syntax I'm giving it. Any ideas?

Active Record

Task.where("(id::text LIKE ?)", "%1%").to_sql
=> "SELECT \"tasks\".* FROM \"tasks\"  WHERE ((id::text LIKE '%1%'))"

Squeel

Task.where{(id::text =~ "%#{criteria}%")}.to_sql
=> "SELECT \"tasks\".* FROM \"tasks\"  WHERE \"id\".\"text\" ILIKE '%criteria%'"

Upvotes: 0

Views: 55

Answers (0)

Related Questions