Rails Associations and db design for Quiz Application

后端 未结 2 1821
难免孤独
难免孤独 2021-01-14 23:52

I am building this quiz application. I want it to be kinda sophisticated.

I have come up with this database schema. But I am really confused.. Confused about what a

2条回答
  •  温柔的废话
    2021-01-15 00:27

    This should do:

    • Drop candidate_answers.test_question
    • Drop the candidate_answers table
    • Drop the test_questions table

      class Test < ActiveRecord::Base has_many :results has_many :questions end

      class Result < ActiveRecord::Base belongs_to :test belongs_to :candidate end

      class Candidate < ActiveRecord::Base has_many :results has_many :answers end

      class Answer < ActiveRecord::Base belongs_to :question belongs_to :candidate end

      class Question < ActiveRecord::Base belongs_to :test has_many :answers end

    It looks like you were intending to reuse the answers for more than one question, that would be a generally bad idea.. Better clone an answer in that case.

提交回复
热议问题