请帮助了解如何@project.payments
拥有此树:
Project
|__Stages
|__Costs
|__Payments
project.rb
has_many :stages
has_many :costs, :through => stages
stage.rb
belongs_to :project
has_many :costs
has_many :payments :through => costs
cost.rb
belongs_to :stage
has_many :payments
payment.rb
belongs_to :cost
答案 0 :(得分:3)
注意:由于这是一个嵌套的has_many:through关系,它只适用于Rails 3.1+(3.1的RC4已经出局)
project.rb
has_many :payments, :through => costs