请帮助了解如何使用此树来进行@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
最佳答案
注意:由于这是一个嵌套的has_many:through关系,因此仅在Rails 3.1+中有效(3.1的RC4已退出)
project.rb
has_many :payments, :through => costs
关于ruby-on-rails - 与has_many建立关联:通过多个模型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6438985/