【问题标题】:How can I set up associations of student, examination, general examination, result如何设置学生、考试、普通考试、结果的关联
【发布时间】:2012-11-09 12:13:29
【问题描述】:

我正在做一个在线考试应用,应用的目的是,它可以让老师创建课程,课程主题和问题(每个问题都有标记),并且老师可以为学生创建考试,学生可以做考试在线的。由于我会使用很多词examinationexaminations,所以我将其简称为examexams

关于我的应用的业务:

  • 教师可以创建主题、问题和每个主题,问题只属于一位教师。
  • 教师可以为一门课程创建general exam,它会从question bank获得一系列问题。
  • 老师会从general exam生成一个number of exams对应number of students需要做课程考试。考试将在生成后自动随机分配给学生。
  • 生成的考试会有不同的number of questions,但每次考试中的total mark of questions 都是一样的。示例,生成考试后:

    Student A take exam with 20 questions, student B take exam only has 10 questions, it means maybe every question in exam of student A only has mark is 1, but questions in exam of student B has mark is 2.

    所以 20 = 10 x 2,这就是我的意思 total mark of questions in every examination will be the same.

我为以下对象设计了表格:

  • 用户(包括学生和教师帐户)
  • 课程
  • 主题
  • 问题
  • 回答

当学生考试时,我认为它会有表格:

  • 结果,包含列:user_id、exam_id、mark

这是我想为general examination 创建的表格:

  • GeneralExamination,列:name、description、dateStart、dateFinish、numberOfMinutes、maxMarkOfExam

但现在我不知道如何在用户(学生)、问题、考试、普通考试之间建立关联。总结联想:

  • 学生可以参加许多考试。
  • 学生只能参加分配给他们的考试。
  • general exam 有很多问题,从题库获得,但每次考试都会从general exam 生成问题。
  • 考试属于一个general examination,用于生成它们。

如何建立这些关联?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 database-design


    【解决方案1】:
    Course has_many :topics belongs_to :teacher
    Topic has_many :questions belongs_to :course belongs_to :teacher
    Question belongs_to :teacher belongs_to :topic has_and_belongs_to_many :general_exams has_and_belongs_to_many :exams
    GeneralExam belongs_to :teacher belongs_to :course has_many :exams has_and_belongs_to_many :questions
    Exam belongs_to :general_exam belongs_to :student has_and_belongs_to_many :questions has_one :exam_result
    Student has_many :exams has_many :exam_results, :through => :exams
    ExamResult belongs_to :exam belongs_to :teacher
    
    class QuestionBank < ActiveRecord::Base
      belongs_to :course
      def questions
        Question.where("topic_id IN (?)", course.topic_ids)
      end
    end
    

    【讨论】:

    • 非常感谢您的帮助hhh :D,特别是关于如何定义关联相关考试,我会参考您的答案,如果没有其他人回答我的问题,我会为您检查接受:) 啊,你能解释一下为什么要添加模型QuestionBank吗?
    • 您应该能够查看是否需要更改任何内容。对于所有 has_and_belongs_to_many 关联,您需要创建一个带有迁移的连接表,请参阅stackoverflow.com/questions/4381154/…
    【解决方案2】:

    我在 something similar 工作,请随时学习、fork 和贡献。

    【讨论】:

    • 太棒了,非常感谢您的分享 :D,10 票给你,哈哈
    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多