我有这堂课:
class Invoice < ActiveRecord::Base
has_many :payments
def payable?
amount_payable != 0
end
end
我怎样才能得到total
所有人payments
的invoice
身份payable
?
class Payment < ActiveRecord::Base
belongs_to :invoice
def self.total
where("invoices.payable? = ?", true).map(&:amount).sum
end
end
问题似乎是该where
子句只接受数据库列名而不接受类似payable?
.
谁能告诉我该怎么做?
谢谢你的帮助。