2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2017-09-05 22:23:34 +03:00
|
|
|
class Question < ApplicationRecord
|
2014-02-09 18:05:57 +02:00
|
|
|
belongs_to :question_type
|
|
|
|
|
has_and_belongs_to_many :conferences
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2014-07-21 14:49:05 +02:00
|
|
|
has_many :qanswers, dependent: :delete_all
|
|
|
|
|
has_many :answers, through: :qanswers, dependent: :delete_all
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2014-11-09 18:25:36 +02:00
|
|
|
validates :title, :question_type_id, presence: true
|
|
|
|
|
validate :existing_answers
|
2014-07-21 14:49:05 +02:00
|
|
|
accepts_nested_attributes_for :answers, allow_destroy: true
|
2014-11-09 18:25:36 +02:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def existing_answers
|
2017-03-28 13:27:52 +05:30
|
|
|
errors.add(:base, 'Must have answers') if answers.blank?
|
2014-11-09 18:25:36 +02:00
|
|
|
end
|
2014-06-30 17:07:53 +02:00
|
|
|
end
|