我试图找到一个user
的逾期invoices
:如何检索Ruby on Rails中的相关记录?
class User < ActiveRecord::Base
def overdue_invoices
invoices.where("overdue = ?", true)
end
end
class Invoice < ActiveRecord::Base
def overdue
balance > 0 && Date.today > due_date
end
end
这个问题似乎是overdue
是在Invoice
模式,而不是数据库列的方法。
无论如何我该如何检索这些记录?这是否甚至是有意义的,还是将这些true
和false
值存储在数据库中会更好?
“Invoice#overdue”方法是什么样的? – 2013-02-17 14:49:19
刚刚在上面添加了它。 “balance”实际上是一个数据库列。 – Tintin81 2013-02-17 15:11:22