4

我正在尝试为多项选择琐事游戏确定最有效的数据库模式。我在电子表格中有问题和答案,列有“question_id”、“level”、“question”、“wrong_ans1”、“wrong_ans2”、“wrong_ans3”、“correct_ans”。

我是否应该将数据分成多个表“问题”,其中包含(id, question, level, is_active)等列和包含(id,choice, is_correct,)等列的“question_choices”

我有一个名为“user_ans”的表,因此我可以跟踪用户玩过的问题以及他们给出的答案。

任何帮助将不胜感激!

4

2 回答 2

2

我会:

  1. 正如您所描述的,将答案保存在一个带有布尔值的表中以指示正确答案。或者 ...
  2. 将答案保存在单个表中,并使用问题模型上的属性来识别正确答案的 ID。这确保只有一个答案是正确的。

在后一种情况下:

Question
  attr_accessible :question, :level, correct_answer_id
  has_many :answers     , :dependent => :destroy
  has_many :user_answers, :through   => :answers

Answer
  attr_accessible :answer, :question_id
  belongs_to :question
  has_many   :user_answers, :dependent => :destroy

User_Answer
  attr_accessible :user_id, :answer_id
  belongs_to :user
  belongs_to :answer

稍微想一想,如果你有很多问题有相同的答案集,但不同的问题对不同的问题是正确的,那么你可以将答案捆绑成组(“蓝色”,“绿色”,“ Red") 并将问题链接到集合 - 在这种情况下,您当然必须在问题级别指出正确答案。

于 2013-06-10T17:23:59.900 回答
0

I would do it like this:

a question model

Question
   attr_accessible :question, :level
   has_many wrong_answers
   has_one correct_answer

Wrong_answer
   attr_accessible :answer, :question_id
   belongs_to :question

Correct_answer
   attr_accessible :answer, :question_id
   belongs_to :question
于 2013-06-10T17:09:16.630 回答