migration and associations

completes #26
This commit is contained in:
Mark Moser
2016-09-15 13:26:31 -05:00
parent 372e86507e
commit 2233d73c39
9 changed files with 54 additions and 2 deletions

View File

@ -2,6 +2,8 @@
class Quiz < ApplicationRecord
has_many :questions, -> { order(:sort) }
has_many :candidates
has_many :reviewer_to_quizzes
has_many :reviewers, through: :reviewer_to_quizzes, source: :user
validates :name, presence: true, uniqueness: true
validates :dept, presence: true

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
class ReviewerToQuiz < ApplicationRecord
belongs_to :user
belongs_to :quiz
end

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
class User < ApplicationRecord
has_secure_password
has_many :candidates, foreign_key: "recruiter_id"
has_many :candidates, foreign_key: :recruiter_id
has_many :reviewer_to_quizzes
has_many :quizzes, through: :reviewer_to_quizzes
validates :email, presence: true, uniqueness: true
validates :name, presence: true