Skip to content

Commit 680e7c0

Browse files
committed
add more deletions for user delete to avoid FK error
1 parent 7b06e8c commit 680e7c0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

app/models/user.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ def bot?
6060
bot
6161
end
6262

63-
def hard_delete
64-
points.update_all user_id: 1 # change to anonymous account id
65-
return unless PointComment.where user_id: id
63+
before_destroy :hard_delete
6664

67-
comments = PointComment.where user_id: id
68-
comments.update_all user_id: 1
65+
def hard_delete
66+
anonymous_id = 1
67+
points.update_all user_id: anonymous_id
68+
documents.update_all user_id: anonymous_id
69+
services.update_all user_id: anonymous_id
70+
point_comments.update_all user_id: anonymous_id
71+
case_comments.update_all user_id: anonymous_id
72+
document_comments.update_all user_id: anonymous_id
73+
service_comments.update_all user_id: anonymous_id
74+
topic_comments.update_all user_id: anonymous_id
75+
DocumentType.where(user_id: id).update_all user_id: anonymous_id
6976
end
7077

7178
def after_database_authentication

0 commit comments

Comments
 (0)