2011-11-04 94 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