I am trying to make a small survey app and started to get a little
confused. So far i have
survey.rb
has_many :answers
answer.rb
belongs_to :survey
So Survey will have many answers, and answer will belong to only one
survey. This part works fine. Now i want to record survey results (you
can only pick ONE answer, it will NOT be a multiple answer survey).
To do this, as far as i know i should create anwsers_surveys table and
setup proper habtm relations or create a new model and go with :through.
Is this the way to go?, since i am not really trying to make a real
habtm between surveys and answers but need to record the results.
Is this the way to go?, since i am not really trying to make a real
habtm between surveys and answers but need to record the results.
Pawel,
Step back from ActiveRecord for a bit and examine your problem domain.
If a survey can have multiple answers and and answer can have multiple
surveys then you have already answered your own question! i.e. you
will need a link table either with the habtm (deprecated) or the first
class model approach (:through)
I write this response with the assumption that “answer” is equivalent to
“result”. If I am mistaken then please forgive the confusion.
why not just have a score column in the answers table?
Yup. So simple solution and it fits just right for my problem. I gotta
start drawing my models and relations on paper before i start making
decisions i guess.
Ilan,
You are right if a survey could have multiple anwsers and answer can
have multiple surveys but that’s not the case. Chris solution fits.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.