2012-07-07 91 views
0

我有這些表: 問題,question_sets。CakePHP模型約定 - 與關係的關係

所以這是與約定一起做的: questions_question_sets。

對不對?接下來,我有這張表: 的答案。

每個questions_question_sets都有很多答案,所以我需要建立一個單獨的列名。它會是: 1. questions_question_set_id或 2. question_question_set_id?

我想這應該是第一次,但誰知道...

回答

0

TLDR:

questions_question_set_id 

的情況下,進一步的細節旁邊的人正在試圖做這樣的事情:

根據您要做的事情,我將假設Question可以屬於多個QuestionSet,並且Answer是特定於QuestionSet內的Question(而不是我認爲合乎邏輯的一個 - Answer屬於Question,無論它在哪個QuestionSet中)。

模型

Question 
QuestionSet 
Answer 
QuestionsQuestionsSet 

questions 
    id 
question_sets 
    id 
answers 
    id 
    questions_question_set_id 
questions_question_sets 
    id 
    question_id 
    question_set_id 

協會

Question hasAndBelongsToMany QuestionSet 
QuestionSet hasAndBelongsToMany Questions 
Answer belongsTo QuestionsQuestionSet 
QuestionsQuestionSet hasMany Answer 

Fields

+0

就是這樣,但它不可能是「邏輯」的方式,因爲每個問題在某些問題集中都有一些屬性(例如,一個問題需要是第一個顯示在一個集合中,例如排在第三位)。無論如何,謝謝你的回答! – smsware 2012-07-07 14:07:16

+0

是的,但它是基於快速設置問題的不同問題的答案嗎? (和NP!很高興幫助!) – Dave 2012-07-07 17:04:53

+0

聽起來更像是你只想在你的questions_question_sets表中的「訂單」字段。 – Dave 2012-07-07 17:06:38