3

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
peresleguine
  • 2,343
  • 2
  • 31
  • 34

1 Answers1

3

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
Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • Oh, this is great, thanks! I'll update my app! I'm just curious, is there a way to do it in Rails 3.0 somehow? – peresleguine Jun 22 '11 at 12:11
  • 1
    Yes, there is. Check out my answer on this question http://stackoverflow.com/questions/6318712/rails-models-relationships/6318745#6318745 – Dogbert Jun 22 '11 at 13:02