开发者

bulding association with has_many :through in multiple models

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜