我有三個型號,每個都具有以下關聯:設置一:的has_many:on Rails的通過一個belongs_to的關聯紅寶石協會
class Model1 < ActiveRecord::Base
has_many :model2s
has_many :model3s
end
class Model2 < ActiveRecord::Base
belongs_to :model1
has_many :model3s, :through => :model1 # will this work? is there any way around this?
end
class Model3 < ActiveRecord::Base
belongs_to :model1
has_many :model2s, :through => :model1 # will this work? is there any way around this?
end
正如你可以在註釋文本看,我剛纔提到我需要什麼。
委託部分給我這個錯誤「委託需要一個目標,提供一個選項散列,其中以:作爲最後一個參數(如:委託:你好,:= =>:greeter)。讓我試試方法部分 – Rohit 2010-10-05 13:45:34
第一種方法是做得很好,並解決我的問題。但請在委託機制中找出一些調整並編輯答案。 :D – Rohit 2010-10-05 13:59:07
使用委託:model3s,:to =>:model1代替委託:model3s,:as =>:model1。 :D適合我 – Rohit 2010-10-05 14:04:14