【发布时间】:2012-08-22 08:25:02
【问题描述】:
我有以下型号:
class Company
# ...
has_many :invoices
end
class Invoice
# ...
belongs_to :company
has_many :items
field :type, String
scope :expense, where(type: 'expense')
scope :income, where(type: 'income')
end
class Item
# ...
belongs_to :invoice
end
问题是如何获取给定公司的所有income 项目?
类似于company.items.expense的东西
【问题讨论】:
标签: ruby-on-rails mongodb mongoid