问题
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