Derp (Caused Retrospring/bugs#41)
This commit is contained in:
parent
5b3b3684c9
commit
563293be44
|
@ -17,10 +17,12 @@ class Answer < ActiveRecord::Base
|
|||
|
||||
before_destroy do
|
||||
# mark a report as deleted if it exists
|
||||
rep = Report.where(target_id: self.id).first
|
||||
unless rep.nil?
|
||||
rep.deleted = true
|
||||
rep.save
|
||||
rep = Report.where(target_id: self.id, type: Reports::Answer)
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
r.save
|
||||
end
|
||||
end
|
||||
|
||||
self.user.decrement! :answered_count
|
||||
|
|
|
@ -14,6 +14,14 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
before_destroy do
|
||||
rep = Report.where(target_id: self.id, type: Reports::Comment)
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
r.save
|
||||
end
|
||||
end
|
||||
|
||||
Subscription.denotify self, answer
|
||||
user.decrement! :commented_count
|
||||
answer.decrement! :comment_count
|
||||
|
|
|
@ -6,10 +6,12 @@ class Question < ActiveRecord::Base
|
|||
validates :content, length: { maximum: 255 }
|
||||
|
||||
before_destroy do
|
||||
rep = Report.where(target_id: self.id).first
|
||||
unless rep.nil?
|
||||
rep.deleted = true
|
||||
rep.save
|
||||
rep = Report.where(target_id: self.id, type: Reports::Question)
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
r.save
|
||||
end
|
||||
end
|
||||
|
||||
user.decrement! :asked_count unless self.author_is_anonymous
|
||||
|
|
|
@ -59,6 +59,25 @@ class User < ActiveRecord::Base
|
|||
end unless website.blank?
|
||||
end
|
||||
|
||||
# when a user deleted himself, all reports relating to the user are invalid
|
||||
before_destroy do
|
||||
rep = Report.where(target_id: self.id, type: Reports::User)
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
r.save
|
||||
end
|
||||
end
|
||||
|
||||
rep = Report.where(user_id: self.id)
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def login=(login)
|
||||
@login = login
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue