我有两个通过连接模型连接的类
class Table
has_many :chairs
has_many :people, through: :chairs
end
class Chair
belongs_to :table
belongs_to :chair
end
class People
has_many :chairs
has_many :tables, through: :chairs
scope :not_paid, -> { where(paid: false) }
end
我想热切地加载人们没有付款的表格,所以我使用了这个:
class Table
has_many :unpaid_people, -> { People.not_paid }, through: :chairs, source: :people
end
Table.includes(:unpaid_people).where(...)
但是这会产生以下错误:
missing FROM-clause entry for table "people"
我如何使这项工作?