|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Trivia quiz model relationshipHi, 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Trivia quiz model relationshipQuestion 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 between Answer and Question. CakePHP can handle that, you just have to define it! When a user is going to give the solution to each question, you would need: User hasMany Solution Solution belongsTo User Solution belongsTo Question Solution belongsTo Answer Enjoy, John On Nov 3, 7:58 am, mupet <muftimas...@...> wrote: > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Trivia quiz model relationshipHi 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 hasAndBelongsToMany answers but also questions hasOne answers? Anyway i will try to baking this tables; Thanks On Tue, Nov 3, 2009 at 8:02 PM, John Andersen <j.andersen.lv@...> wrote: > > 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 between Answer and > Question. CakePHP can handle that, you just have to define it! > > When a user is going to give the solution to each question, you would > need: > User hasMany Solution > Solution belongsTo User > Solution belongsTo Question > Solution belongsTo Answer > > Enjoy, > John > > > On Nov 3, 7:58 am, mupet <muftimas...@...> wrote: >> 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 > > > -- Mufti Ali 087831163105 http://wordtaps.com http://blogfreakz.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Trivia quiz model relationshipActually 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 Answer for the correct Answer, so that Question belongsTo Answer - not the other way around. This I saw only when I tried to define the actual tables above. Whether or not you can bake this, I have no idea, I always create my models and tables by hand or in another tool. Enjoy, John On Nov 3, 8:04 pm, mufti ali <muftimas...@...> wrote: > 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 hasAndBelongsToMany > answers but also questions hasOne answers? > > Anyway i will try to baking this tables; > > Thanks > > > > On Tue, Nov 3, 2009 at 8:02 PM, John Andersen <j.andersen...@...> wrote: > > > 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 between Answer and > > Question. CakePHP can handle that, you just have to define it! > > > When a user is going to give the solution to each question, you would > > need: > > User hasMany Solution > > Solution belongsTo User > > Solution belongsTo Question > > Solution belongsTo Answer > > > Enjoy, > > John > > > On Nov 3, 7:58 am, mupet <muftimas...@...> wrote: > >> 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 > > -- > Mufti Ali > 087831163105http://wordtaps.comhttp://blogfreakz.com You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Trivia quiz model relationshipI 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 <j.andersen.lv@...> wrote: > > 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 > Answer for the correct Answer, so that Question belongsTo Answer - not > the other way around. This I saw only when I tried to define the > actual tables above. > > Whether or not you can bake this, I have no idea, I always create my > models and tables by hand or in another tool. > Enjoy, > John > > On Nov 3, 8:04 pm, mufti ali <muftimas...@...> wrote: >> 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 hasAndBelongsToMany >> answers but also questions hasOne answers? >> >> Anyway i will try to baking this tables; >> >> Thanks >> >> >> >> On Tue, Nov 3, 2009 at 8:02 PM, John Andersen <j.andersen...@...> wrote: >> >> > 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 between Answer and >> > Question. CakePHP can handle that, you just have to define it! >> >> > When a user is going to give the solution to each question, you would >> > need: >> > User hasMany Solution >> > Solution belongsTo User >> > Solution belongsTo Question >> > Solution belongsTo Answer >> >> > Enjoy, >> > John >> >> > On Nov 3, 7:58 am, mupet <muftimas...@...> wrote: >> >> 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 >> >> -- >> Mufti Ali >> 087831163105http://wordtaps.comhttp://blogfreakz.com > > > -- Mufti Ali 087831163105 http://wordtaps.com http://blogfreakz.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |