2011-10-31 143 views
1

我有如下兩種型號:Rails,ActiveModel模型關聯?

User 
Mentions (user_id, mentioned_by) 

@ mention.user給我的創造者,但我需要誰是提給用戶。我想這樣做:@neartment.mentioner獲得user_id提到_by

如何在模型中設置該關係?我試過了:

User.rb: 
    has_many :mentions 


Mention.rb 
belongs_to :user 
belongs_to :user, :as => "mentioner", :foreign_key => "mentioned_by" 

但是那個錯誤。想法?由於

回答

3

mention.rb,試試這個:

belongs_to :user 
belongs_to :mentioner, :class_name => "User", :foreign_key => "mentioned_by" 
+0

真棒。謝謝 –