2014-10-27 22:36:38 -07:00
|
|
|
class Answer < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :question
|
2014-11-30 10:43:22 -08:00
|
|
|
has_many :comments, dependent: :destroy
|
|
|
|
has_many :smiles, dependent: :destroy
|
2014-12-14 05:34:51 -08:00
|
|
|
|
|
|
|
def notification_type(*_args)
|
|
|
|
Notifications::QuestionAnswered
|
|
|
|
end
|
2014-12-28 12:20:07 -08:00
|
|
|
|
|
|
|
def remove
|
|
|
|
self.user.decrement! :answered_count
|
|
|
|
self.question.decrement! :answer_count
|
|
|
|
self.smiles.each do |smile|
|
|
|
|
Notification.denotify self.user, smile
|
|
|
|
end
|
|
|
|
self.comments.each do |comment|
|
|
|
|
comment.user.decrement! :commented_count
|
|
|
|
Notification.denotify self.user, comment
|
|
|
|
end
|
|
|
|
Notification.denotify self.question.user, self
|
|
|
|
self.destroy
|
|
|
|
end
|
2014-10-27 22:36:38 -07:00
|
|
|
end
|