0

I am trying to model an exam object and wanted to your opinions.

In a exam, there are multiple types of question, like Multiple Choice (MC), Short Question (SQ), True or False (TF), etc..

Each types of question has its own data, for example: (MC) would need question, potential answers, correct answer and (SQ) would only need a question.

Originally, I was thinking to just have an Exam model and a Question model (with single table inheritance) for the different type of question. However, since different types of question behaves differently and have different data attributes, I don't think that's going to work.

What I am thinking now is to have a Exam object which has_many "ExamQuestion" object which has attributes (exam_id, question_type, question_id).

I think this is going to work, but kinda don't like the fact that I have to have a column like 'question_type' in the "cross section" table like "ExamQuestion". ex. the query might become ugly.

Does anyone see a better way of doing this?

Thanks!

Herman
  • 3,004
  • 5
  • 37
  • 49

2 Answers2

0

If you're using normal model inheritance that's how it works by default, though (STI: single-table inheritance)--you don't deal with it manually.

See here for some info on MTI, or this prior SO answer.

Community
  • 1
  • 1
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
0

I believe this post may give you some ideas in one approach you could use to solve this. You can check my answer in there to see if it helps.

Modeling Inheritance with Ruby Rails ORM

Does that address what you're looking for or are you in need of something else?

Community
  • 1
  • 1
Kristian PD
  • 2,705
  • 1
  • 19
  • 22