我有以下关系
class Invoice
has_many :entries
has_many :price_matrixes, through: entries
end
class Entry
belongs_to :invoice
belongs_to :price_matrix
end
class PriceMatrix
has_many :entries
has_many :invoices, through: entries
end
现在,我有一组 price_matrix id,例如 [1, 2],并且我想找到只有这两个价格矩阵的所有发票。
注意:试过这个Invoice.includes(:price_matrixes).where(price_matrixes: {id: [1, 2]}),但这应该返回记录,即使列表中的一个 id 将匹配。