diff --git a/pkg/models/deletion/delete_user.go b/pkg/models/deletion/delete_user.go index fc6a659..702ded9 100644 --- a/pkg/models/deletion/delete_user.go +++ b/pkg/models/deletion/delete_user.go @@ -223,6 +223,17 @@ func DeleteForumThreads(userID uint64) error { // Wipe all these threads and their comments. if len(threadIDs) > 0 { + // First, delete the threads - so they won't be referring to comment_ids that we + // delete next and causing errors to arise. + result = models.DB.Where( + "id IN ?", + threadIDs, + ).Delete(&models.Thread{}) + if result.Error != nil { + return fmt.Errorf("Couldn't delete your forum threads: %s", result.Error) + } + + // Remove the comments. result = models.DB.Where( "table_name = ? AND table_id IN ?", "threads", threadIDs, @@ -231,11 +242,6 @@ func DeleteForumThreads(userID uint64) error { return fmt.Errorf("Couldn't wipe threads of comments: %s", result.Error) } - // And finish the threads off too. - result = models.DB.Where( - "id IN ?", - threadIDs, - ).Delete(&models.Thread{}) return result.Error }