Rails 4条件包括has_many through

时间:2016-10-27 22:26:26

标签: ruby-on-rails activerecord

我有两个通过连接模型连接的类

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"

我如何使这项工作?

0 个答案:

没有答案