2011-03-09 89 views
7
Project 
has_many :tasks 

Task 
has_many :invoices, :through => :line_items 
has_many :line_items 

LineItems 
belongs_to :invoice 
belongs_to :task 

Invoice 
has_many :tasks, :through=> :line_item 
has_many :line_items 

我想從項目的has_many關聯:發票:通過=>:任務:的has_many:通過協會兩層深

當我嘗試了,我得到:

源反射宏無效:has_many:through for has_many:invoices,:through =>:tasks。使用:source來指定源反射。

我有點茫然,如果這是可能的,如果是這樣,如何使用:源正確

回答

5

瑞安是正確的,這是從Rails的3.1支持。從發行說明中提取:

與a:through選項的關聯現在可以使用任何關聯作爲直通或源關聯,包括具有:直通選項和has_and_belongs_to_many關聯的其他關聯。

Src:http://guides.rubyonrails.org/3_1_release_notes.html