This feels like it should be super simple, but for the life of me I haven't been able to get it right.
In my application, I want to have Questions and Answers.
A Question can only have 1 Answer, but an Answer can be used for many Questions.
For example.
Question Table Data
- "Two plus Two equals?"
- "Number of sides to a square?"
Answer Table Data
- Four
Both Questions only have 1 Answer, but the Answer record can be used for both Questions.
I thought maybe this would work ::
rails g resource question verbiage:string answer:references
but then I have to put a belongs_to :answer on the Question model and that doesn't seem right.
It feels like it should be possible to do something like ::
Question.first.answer # returns the single answer
Answer.first.questions # returns all of the Questions where this record is the Answer
Can anyone educate me on the proper way to model this in ActiveRecord?