Created
May 23, 2011 13:15
-
-
Save boyvanamstel/986670 to your computer and use it in GitHub Desktop.
Multiple relations to the same model in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model User: | |
has_many :questions | |
has_many :comments | |
# Questions to which the user is an expert a.k.a. 'questions to me' | |
has_many :experts, :dependent => :destroy | |
has_many :questionstome, :through => :experts, :source => :question | |
# This allows you to do things like this: | |
# u = User.first | |
# u.questions.all # lists all questions asked by the user | |
# u.questionstome.all # lists all questions to which someone made me an expert |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment