stevenbeales /
mental-test
| 1 | # frozen_string_literal: true |
||
| 2 | |||
| 3 | # Association class between participants and surveys |
||
| 4 | class SurveyParticipant < ApplicationRecord |
||
| 5 | belongs_to :participant, inverse_of: :survey_participants |
||
| 6 | belongs_to :survey, inverse_of: :survey_participants |
||
| 7 | |||
| 8 | validates :participant, presence: true |
||
| 9 | validates :survey, presence: true |
||
| 10 | |||
| 11 | validates_uniqueness_of :survey, scope: :participant |
||
| 12 | validates_uniqueness_of :participant, scope: :survey |
||
| 13 | View Code Duplication | ||
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 14 | def to_s |
||
| 15 | "#{participant} #{survey}" |
||
| 16 | end |
||
| 17 | end |
||
| 18 | |||
| 19 | # == Schema Information |
||
| 20 | # |
||
| 21 | # Table name: survey_participants |
||
| 22 | # |
||
| 23 | # id :integer not null, primary key |
||
| 24 | # participant_id :integer not null |
||
| 25 | # survey_id :integer not null |
||
| 26 | # created_at :datetime not null |
||
| 27 | # updated_at :datetime not null |
||
| 28 | # |
||
| 29 | # Indexes |
||
| 30 | # |
||
| 31 | # index_by_participant_survey (participant_id,survey_id) UNIQUE |
||
| 32 | # index_survey_participants_on_participant_id (participant_id) |
||
| 33 | # index_survey_participants_on_survey_id (survey_id) |
||
| 34 | # |
||
| 35 |