如何设置学生,考试,一般考试,成绩的关联

时间:2012-11-09 12:13:29

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

我正在建立一个在线考试应用程序,应用程序的目的是,它可以让教师创建课程,课程主题和问题(每个问题都有标记),教师可以为学生和学生创建考试在线做考试。由于我将使用多个单词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,用于生成它们。

我如何设置这些关联?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

我正在研究something similar,随时学习,分叉和贡献。