I think this model relationship more better, so we have
[answers_questions] for HABTM relationship, Question belongsTo Answer.
I will try bake again with this model. Maybe i need modify some view manualy.
Again, thanks john, very helpfull
On Wed, Nov 4, 2009 at 1:05 PM, John Andersen
Hi, i will create trivia quiz application using cakePHP, i have
trouble on designing model reationship.
In this case i have question, answers and correct answer.
which is One question have 3 optional answers but have only 1 correct
answers. How to design model relationship?
Thanks and regards
Question hasMany optional Answer
Question hasOne correct Answer
What you then need is only the models to define the trivias:
Question hasAndBelongsToMany Answer
Answer hasAndBelongsToMany Question
Question hasOne Answer
Answer belongsTo Question
Do observe that there are two associations
Hi john, thanks for your useful solution.
So, in this case we have 2 tables on my database.
1. questions
2. answers
questions hasAndBelongsToMany answers
Answer hasAndBelongsToMany questions
questions hasOne answers
answers belongsTo questions
There is no troble or conflict when questions
Actually you will have 3 tables:
questions, answers and answers_questions
Something like the following:
[questions]
id
question
answer_id - the correct answer
[answers]
id
answer
[answers_questions]
id
answer_id
question_id
Observe that I changed the relation between the Question and the