我想获得发票的集合,这是不是尚未完成的借记的一部分。Rails协会:通过不存在
所以每个发票没有付款必须存在未完成 因此,无论与被完成NO借方或发票,只有借记发票是有效
发票具有的has_many关系借记通过加盟模式InvoiceDebit
class Invoice < ActiveRecord::Base
has_many :debit_invoices
has_many :debits, :through => :debit_invoices
end
class DebitInvoice < ActiveRecord::Base
belongs_to :invoice
belongs_to :debit
end
class Debit < ActiveRecord::Base
attr_accessible :completed
has_many :debit_invoices
has_many :invoices, :through => :debit_invoices
end
我宁愿不写出SQL中的整个查询,因为我已经使用AREL来限制只有当前登录用户的发票池。
所以,你要对此有不完成的值是假的存在借记所有发票? –
这就是我阅读OP的声明的方式。同样,所有确实存在的借记都已经完成的发票。 – Chowlett
您是否在DebitInvoice中设置了正确的'foreign_keys'? (IE'invoice_id'和'debit_id'? –