Postgres Rails 4 搜索查询 id 或多列

Postgres Rails 4 search query id or multiple columns

我正在使用带有 Heroku 基本搜索表单的应用程序工作,但我无法使我的 sql 查询与 PostgreSQL 一起正常工作,即使此查询与 MySQL 一起工作。顺便说一下,我试图从 Heroku 粘贴日志,但它只说当你搜索它呈现的东西时 500.html.

这是我的带有搜索操作的模型 OrdemDeServico:

def self.search(search)
   if search
    joins(:cliente).where("clientes.nome LIKE ? OR veiculo LIKE ? OR placa LIKE  ? OR ordem_de_servicos.id = ?", "%#{search}%", "%#{search}%", "%#{search}%", "#{search}")
   else
    where(nil)
   end
  end

我刚在本地安装了PostgreSQL,搜索时返回这个错误:

`PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "Augusto"
LINE 1: ... placa LIKE '%Augusto%' OR ordem_de_servicos.id = 'Augusto')

查询:

SELECT  "ordem_de_servicos".* FROM "ordem_de_servicos" INNER JOIN "clientes" ON "clientes"."id" = "ordem_de_servicos"."cliente_id" WHERE (clientes.nome LIKE '%Augusto%' OR veiculo LIKE '%Augusto%' OR placa LIKE '%Augusto%' OR ordem_de_servicos.id = 'Augusto')  ORDER BY prazo LIMIT 5 OFFSET 0

我终于找到了解决办法。那些有同样问题的人这是我的模型代码:

def self.search(search)
    if search
        where("id = ?", search)
        joins(:cliente).where("clientes.nome ilike :q or veiculo ilike :q or placa ilike :q", q: "%#{search}%")
    else
        where(nil)
    end
end