2012-11-09 75 views
1

我正在建立一個在線考試應用程序,應用的目的是,它可以允許教師創建課程,課程主題和問題(每個問題都有標記),教師可以爲學生創建考試,學生可以在線進行考試。由於我將使用許多字examinationexaminations,所以我將它稱爲examexams縮短。我如何設置學生,考試,一般考試,結果協會

關於我的應用程序的業務:

  • 教師可以創建主題,問題和每一個主題,問題只屬於一個老師。
  • 教師可以爲一療程創建general exam,它會得到問題的集合從question bank
  • 從這個general exam,老師會產生與number of students需要做課程的考試相對應的number of exams。考試將在生成後自動分配給學生並隨機分配。
  • 考試產生都會有不同的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×2,這是我用於total mark of questions in every examination will be the same.

我已經設計表:

  • 用戶(包括學生和教師帳戶)
  • 主題
  • 問題
  • 回答

當學生做檢查,我認爲這將有表:

  • 結果,列:USER_ID,exam_id,標誌着

這是我想我會創建的表格general examination

  • GeneralExamination,與列:名稱,描述,dateStart,dateFinish,numberOfMinutes,maxMarkOfExam

但現在我不知道如何建立用戶之間的(學生)問題的考試協會,一般考試。總結協會:

  • 學生可以做很多考試。
  • 學生只能做分配給他們的考試。
  • 一個general exam,有許多問題,從問題銀行裏,但每次考試都會獲得問題從general exam生成它們。
  • 考試屬於一個general examination,用於生成它們。

我該如何設置這些關聯?

回答

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 
+0

感謝您的幫助so muchhhh:D,特別是關於如何定義協會相關考試,我會參考你的答案,如果沒有人回答我的問題,我會檢查接受你:)啊,你能解釋爲什麼添加模型'QuestionBank'? – Thanh

+0

您應該能夠看到是否需要更改任何內容。對於所有has_and_belongs_to_many關聯,您將需要使用遷移創建連接表,請參閱http://stackoverflow.com/questions/4381154/rails-migration-for-has-and-belongs-to-many-join-table – mrbrdo

+0

我會看看它,非常感謝。 – Thanh