用的has_many BULDING关联关系:通过多种模式 [英] bulding association with has_many :through in multiple models
本文介绍了用的has_many BULDING关联关系:通过多种模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助了解如何做 @ project.payments
有这个树:
项目
| __Stages
| __Costs
| __Payments
project.rb
的has_many:阶段
的has_many:成本:通过= GT;阶段
stage.rb
belongs_to的:项目
的has_many:成本
的has_many:付款:通过=>成本
cost.rb
belongs_to的:第一阶段
的has_many:金
payment.rb
belongs_to的:成本
解决方案
注:由于这是一个嵌套的has_many:通过关系,将只在Rails的工作3.1+(3.1 RC4是出)
project.rb
的has_many:付款:通过=>成本
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
解决方案
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
这篇关于用的has_many BULDING关联关系:通过多种模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文