Just as on StackOverflow, in my app a User can write Questions and can also provide Answers:
class User < ActiveRecord::Base
has_many :questions
has_many :answers
end
class Question < ActiveRecord::Base
has_many :answers
belongs_to :user
end
class Answer < ActiveRecord::Base
belongs_to :question
belongs_to :user
end
My question has to do with the Answer model above:
Is it ok for an Answer
to belong_to
both the User and the Question models?
I have a feeling I read somewhere that a model can only have a single foreign key. If so, how do I rectify that?