bulding association with has_many :through in multiple models

我的梦境 提交于 2019-12-10 18:47:07

问题


Please help to understand how to do @project.payments having this tree:

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

回答1:


Note: As this is a nested has_many :through relationship, it'll only work in Rails 3.1+ (RC4 of 3.1 is out)

project.rb

has_many :payments, :through => costs


来源:https://stackoverflow.com/questions/6438985/bulding-association-with-has-many-through-in-multiple-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!