【发布时间】:2017-12-29 18:03:20
【问题描述】:
这是我的模型 - 首先:
class Negocio < ApplicationRecord
has_many :cuenta_clientes
end
秒
class CuentaCliente < ApplicationRecord
belongs_to :negocio
has_many :pago_clientes
end
第三个:
class PagoCliente < ApplicationRecord
belongs_to :cuenta_cliente
end
我想选择 Negocio 拥有的所有 PagoCliente。但是 Negocio 和 PagoCliente 之间没有引用(我不能修改表和关系)所以这是我的尝试:
pagos = PagoCliente.joins(cuenta_cliente: :negocio).where(negocio: {id: params[:negocio_id}])
但这是我的错误输出:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "negocio"
LINE 1: ...cios"."id" = "cuenta_clientes"."negocio_id" WHERE "negocio"....
那么,这个查询的正确语法是什么?谢谢。我正在使用 Postgres...
【问题讨论】:
标签: sql ruby-on-rails ruby activerecord