2011-11-04 96 views
2

我有幾個富人加入模型,我想知道是否有可能或Rails約定有以下幾點:Rails的豐富的聯想

has_many :users through => rich_association_one 
has_many :rich_association_one 

has_many :users through => rich_accociation_two 
has_many :rich_association_two 

感謝

回答

4

有可能的,但我想你會必須使用不同的別名 - 正如您所期望的那樣,我認爲兩次撥打has_many :users會給您的模型帶來厄運。

嘗試是這樣的:在has_many選項

has_many :rich_association_one 
has_many :association_one_users, 
     :through => :rich_association_one, 
     :class_name => "User" 

has_many :rich_association_two 
has_many :association_two_users, 
     :through => rich_accociation_two, 
     :class_name => "User" 

更基本的信息可以用RoR guides