2014-02-09 18:05:57 +02:00
|
|
|
class Answer < ActiveRecord::Base
|
|
|
|
|
attr_accessible :title
|
2014-08-18 21:26:45 +03:00
|
|
|
|
2015-09-10 12:39:52 +03:00
|
|
|
has_many :qanswers, dependent: :destroy
|
2014-07-21 14:49:05 +02:00
|
|
|
has_many :questions, through: :qanswers
|
2014-02-09 18:05:57 +02:00
|
|
|
|
2014-07-21 14:49:05 +02:00
|
|
|
validates :title, presence: true
|
2015-09-10 12:39:52 +03:00
|
|
|
validate :no_modification_if_used
|
|
|
|
|
|
|
|
|
|
def no_modification_if_used
|
|
|
|
|
errors.add('', 'cannot be altered or deleted, if they are being used.') if self.title_changed? && self.questions.any?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Gets answer, question, conference
|
|
|
|
|
## Returns
|
|
|
|
|
# the amount of replies for a given answer
|
|
|
|
|
# + integer +
|
|
|
|
|
def sum_replies question, conference
|
|
|
|
|
self.qanswers.find_by(question: question).registrations.where(conference: conference).count
|
|
|
|
|
end
|
2014-02-09 18:05:57 +02:00
|
|
|
end
|