Reputation: 815
I have the follow two models:
User
Mentions (user_id, mentioned_by)
@mention.user gives me the creator, but I need the user who was mention. I would like to do: @mention.mentioner which gets the user_id with mentioned_by
How do I set that relationship in the models? I tried:
User.rb:
has_many :mentions
Mention.rb
belongs_to :user
belongs_to :user, :as => "mentioner", :foreign_key => "mentioned_by"
But that errors. Ideas? Thanks
Upvotes: 1
Views: 398
Reputation: 124409
In mention.rb
, try this:
belongs_to :user
belongs_to :mentioner, :class_name => "User", :foreign_key => "mentioned_by"
Upvotes: 3