Ruby on rails 在多个模型中建立与多个:通过的关联

Ruby on rails 在多个模型中建立与多个:通过的关联,ruby-on-rails,associations,Ruby On Rails,Associations,请帮助了解如何使用此树进行@project.payments: Project |__Stages |__Costs |__Payments project.rb has_many :stages has_many :costs, :through => stages has_many :payments, :through => costs stage.rb belongs_to :project has_many :c

请帮助了解如何使用此树进行
@project.payments

Project
   |__Stages
         |__Costs
              |__Payments
project.rb

 has_many :stages
 has_many :costs, :through => stages
has_many :payments, :through => costs
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

注意:由于这是一个嵌套的has_many:through关系,因此它只能在Rails 3.1+中工作(3.1中的RC4已退出)

project.rb

 has_many :stages
 has_many :costs, :through => stages
has_many :payments, :through => costs

哦,太好了,谢谢!我将更新我的应用程序!我只是好奇,在Rails 3.0中有没有办法做到这一点?是的,有。看看我对这个问题的回答