1

I'm building an online examination application, the purpose of app is, it can allow teacher create courses, topics of course, and questions (every question has mark), and teacher can create examinations for students and students can do examinations online. As I will use many word examination and examinations, so i will call it exam and exams for shorter.

About business of my app:

  • Teacher can create topics, questions and every topic, question only belongs to one teacher.
  • Teacher can create a general exam for a course, it will get a collection of questions from question bank.
  • From that general exam, teacher will generate and a number of exams corresponding with number of students need to do course's exam. Exams will be assigned to students auto and random after generated.
  • Exams are generated will have different number of questions, but the total mark of questions in every exam will be the same. Example, after exams generated:

    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.

    So 20 = 10 x 2, this is what i means total mark of questions in every examination will be the same.

I have designed tables for:

  • User (include students and teachers account)
  • Course
  • Topic
  • Question
  • Answer

When students do exam, I think it will have table:

  • Result, with columns: user_id, exam_id, mark

This is table i think i will create for general examination:

  • GeneralExamination, with columns: name, description, dateStart, dateFinish, numberOfMinutes, maxMarkOfExam

But now i don't know how to set up associations between user(student), question, exam, general exam. To sum up associations:

  • Student can do many exams.
  • Students only can do exams which assigned to them.
  • A general exam has many questions, got from question bank, but every exam will get questions from general exam generated them.
  • Exams belongs to one general examination, which used to generated them.

How can i set up those associations?

Thanh
  • 8,219
  • 5
  • 33
  • 56

2 Answers2

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
mrbrdo
  • 7,968
  • 4
  • 32
  • 36
  • Thanks for your help so muchhhh :D, specially about how to define associations related exams, i will reference your answer, and if no one else answer my question, i will check accept for you :) Ah, can you explain why add model `QuestionBank`? – Thanh Nov 09 '12 at 13:16
  • You should be able to see if you need to change anything. For all the has_and_belongs_to_many associations you will need to create a join table with a migration, see http://stackoverflow.com/questions/4381154/rails-migration-for-has-and-belongs-to-many-join-table – mrbrdo Nov 09 '12 at 13:19
1

I'm working on something similar, feel free to study, fork and contribute.

maxcobmara
  • 391
  • 2
  • 9