title: RoR model relationship suggestion needed
body: <p>I have 3 models category, question and quiz and 5 tables categories, questions, quizzes, category_quizzes, and questions_quizzes.</p>
  
  <p>A quiz has many questions and may belongs to zero or more categories. Also a question may belongs to many quizzes</p>
  
  <p>Can some body suggest how should be the relationship between the models</p>
  
  <p>table schema follows</p>
  
  <pre><code>CREATE TABLE categories (
    id int(11) unsigned NOT NULL auto_increment,
    title varchar(255) NOT NULL,
    PRIMARY KEY  (id),
  );
  
  CREATE TABLE category_quizzes (
    id int(11) unsigned NOT NULL auto_increment,
    category_id int(11) unsigned NOT NULL,
    quiz_id int(11) unsigned NOT NULL,
    PRIMARY KEY  (id),
    KEY category_id (category_id,quiz_id),
    KEY quiz_id (quiz_id)
  );
  
  CREATE TABLE questions (
    id int(11) unsigned NOT NULL auto_increment,
    question varchar(255) NOT NULL,
    answer varchar(255) NOT NULL,
    PRIMARY KEY  (id),
  );
  
  CREATE TABLE questions_quizzes (
    id int(11) unsigned NOT NULL auto_increment,
    quiz_id int(11) unsigned NOT NULL,
    question_id int(11) unsigned NOT NULL,
    PRIMARY KEY  (id),
    KEY quiz_id (quiz_id,question_id),
    KEY question_id (question_id)
  );
  
  CREATE TABLE quizzes (
    id int(11) unsigned NOT NULL auto_increment,
    title varchar(255) NOT NULL,
    PRIMARY KEY  (id),
  );
  </code></pre>
  
  <p>My current model classes</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
      has_and_belongs_to_many :quiz
  end
  
  class Question &lt; ActiveRecord::Base
      has_and_belongs_to_many :quiz
  end
  
  class Quiz &lt; ActiveRecord::Base
    has_many   :questions
    has_and_belongs_to_many :categories
  end
  </code></pre>