Using a join model to relate a model to itself

Posted by Gabe Hollombe on Stack Overflow See other posts from Stack Overflow or by Gabe Hollombe
Published on 2010-05-19T04:43:22Z Indexed on 2010/05/19 4:50 UTC
Read the original article Hit count: 268

Filed under:
|

I have two models:

  • User
  • MentoringRelationship

MentoringRelationship is a join model that has a mentor_id column and a mentee_id column (both of these reference user_ids from the users table).

How can I specify a relation called 'mentees' on the User class that will return all of the users mentored by this user, using the MentoringRelationships join table? What relations do we need to declare in the User model and in the MentoringRelationship model?

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about ruby-on-rails