1

私はオンライン試験アプリケーションを作成しています。このアプリの目的は、教師がコース、コースのトピック、および質問を作成できるようにすることです(すべての質問にマークが付いています)。教師は学生向けの試験を作成でき、学生はオンラインで試験を行うことができます。多くの単語examinationとを使用するexaminationsので、それexamexams短くします。

私のアプリのビジネスについて:

  • 教師はトピック、質問、およびすべてのトピックを作成できます。質問は1人の教師にのみ属します。
  • 教師は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

しかし、今はユーザー(学生)、質問、試験、一般試験の間の関連付けを設定する方法がわかりません。関連付けを要約するには:

  • 学生は多くの試験を行うことができます。
  • 学生は自分に割り当てられた試験のみを行うことができます。
  • Ageneral examには多くの質問があり、質問バンクから取得しますが、すべての試験はgeneral exam生成された質問から取得します。
  • general examination試験は、それらを生成するために使用された1つに属しています。

これらの関連付けを設定するにはどうすればよいですか?

4

2 に答える 2

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
于 2012-11-09T13:05:28.317 に答える
1

私は似たようなことに取り組んでいます。気軽に勉強して、フォークして、貢献してください。

于 2012-11-09T15:10:50.643 に答える