diff --git a/app/models/answer.rb b/app/models/answer.rb index 5678c566..52568fa8 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -17,7 +17,7 @@ class Answer < ActiveRecord::Base before_destroy do # mark a report as deleted if it exists - rep = Report.where(target_id: self.id, type: Reports::Answer) + rep = Report.where(target_id: self.id, type: 'Reports::Answer') rep.each do |r| unless r.nil? r.deleted = true diff --git a/app/models/comment.rb b/app/models/comment.rb index c23070ca..abc04dbe 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -14,7 +14,7 @@ class Comment < ActiveRecord::Base end before_destroy do - rep = Report.where(target_id: self.id, type: Reports::Comment) + rep = Report.where(target_id: self.id, type: 'Reports::Comment') rep.each do |r| unless r.nil? r.deleted = true diff --git a/app/models/question.rb b/app/models/question.rb index 1771b6bc..adc95c59 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -6,7 +6,7 @@ class Question < ActiveRecord::Base validates :content, length: { maximum: 255 } before_destroy do - rep = Report.where(target_id: self.id, type: Reports::Question) + rep = Report.where(target_id: self.id, type: 'Reports::Question') rep.each do |r| unless r.nil? r.deleted = true diff --git a/app/models/user.rb b/app/models/user.rb index 832b4e20..c991e2a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,7 @@ class User < ActiveRecord::Base # 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 = Report.where(target_id: self.id, type: 'Reports::User') rep.each do |r| unless r.nil? r.deleted = true @@ -161,7 +161,7 @@ class User < ActiveRecord::Base # region stuff used for reporting/moderation def report(object, reason = nil) - existing = Report.find_by(target_id: object.id, user_id: self.id, deleted: false) + existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, deleted: false) if existing.nil? Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, reason: reason) elsif not reason.nil? and reason.length > 0