与has_many建立联系:通过多个模型
请帮助了解如何使用此树执行@project.payments
:
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
注意:由于这是一个嵌套的has_many:through关系,它只适用于Rails 3.1+(3.1的RC4出来)
project.rb
has_many :payments, :through => costs