I’m developing a poll feature that allows users to create poll questions with options and allow other users to answer them
The answer model includes an option_id column but the two models are not related.
I have two questions:
- Do my models (below) fully encapsulate what I’m trying to represent?
- How would the create method for an
answercontroller action look? (Specifically, how to retrieve theoption_id)
Note: I’ve never dealt with this pattern in which a model(answer) references another model (option) via option_id but the two aren’t related
So far I have this:
class Question < ActiveRecord::Base
belongs_to :user
has_many :options
has_many :answers
end
class Option < ActiveRecord::Base
belongs_to :question
end
class Answer < ActiveRecord::Base
belongs_to :user
belongs_to :question
end
Found a tut for a mobile app doing this