title: How can I set up associations of student, examination, general examination, result
body: <p>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 <code>examination</code> and <code>examinations</code>, so i will call it <code>exam</code> and <code>exams</code> for shorter.</p>
  
  <p>About business of my app:  </p>
  
  <ul>
  <li>Teacher can create topics, questions and every topic, question only belongs to one teacher.</li>
  <li>Teacher can create a <code>general exam</code> for a course, it will get a collection of questions from <code>question bank</code>.</li>
  <li>From that <code>general exam</code>, teacher will generate and a <code>number of exams</code> corresponding with <code>number of students</code> need to do course's exam. Exams will be assigned to students auto and random after generated.</li>
  <li><p>Exams are generated will have different <code>number of questions</code>, but the <code>total mark of questions</code> in every exam will be the same. Example, after exams generated: </p>
  
  <p><code>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.</code></p>
  
  <p>So 20 = 10 x 2, this is what i means <code>total mark of questions in every examination will be the same.</code></p></li>
  </ul>
  
  <p>I have designed tables for:  </p>
  
  <ul>
  <li>User (include students and teachers account)  </li>
  <li>Course  </li>
  <li>Topic  </li>
  <li>Question   </li>
  <li>Answer</li>
  </ul>
  
  <p>When students do exam, I think it will have table:</p>
  
  <ul>
  <li>Result, with columns: user_id, exam_id, mark  </li>
  </ul>
  
  <p>This is table i think i will create for <code>general examination</code>:</p>
  
  <ul>
  <li>GeneralExamination, with columns: name, description, dateStart, dateFinish, numberOfMinutes, maxMarkOfExam </li>
  </ul>
  
  <p>But now i don't know how to set up associations between user(student), question, exam, general exam. To sum up associations:</p>
  
  <ul>
  <li>Student can do many exams.</li>
  <li>Students only can do exams which assigned to them.</li>
  <li>A <code>general exam</code> has many questions, got from question bank, but every exam will get questions from <code>general exam</code> generated them.</li>
  <li>Exams belongs to one <code>general examination</code>, which used to generated them.</li>
  </ul>
  
  <p>How can i set up those associations? </p>