在多个模型中与 has_many :through 建立关联

2024-05-28

请帮助了解该怎么做@project.payments有这棵树:

Project
   |__Stages
         |__Costs
              |__Payments

项目.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

付款.rb

belongs_to :cost

注意:由于这是一个嵌套的 has_many :through 关系,因此它仅适用于 Rails 3.1+(3.1 的 RC4 已发布)

项目.rb

has_many :payments, :through => costs
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在多个模型中与 has_many :through 建立关联 的相关文章

随机推荐