# Using topic.destroy(id) to delete illegal content

**URL:** https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239
**Category:** Development
**Created:** [March 30, 2018, 5:00pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239 "2018-03-30T17:00:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [March 30, 2018, 5:00pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239/1 "2018-03-30T17:00:58Z")

</div>

My goal was to delete a topic from the DB due to legal reasons.

so I ran the command:

> root@he-ps09-superstars:/var/www/discourse# echo “Topic.destroy(id)” | rails c

The topic was deleted 👍

The category still thinks there is 1 topic and I cannot delete the category.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [March 30, 2018, 6:17pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239/2 "2018-03-30T18:17:49Z")

</div>

What other tables cross index the topic id?  
Did you delete those rows as well?  
What other tables cross index fields in those other tables?  
Did you delete those rows?  
rinse - repeat - until all are deleted.

IMHO it is much safer and a lot simpler to “delete” a topic using the UI than to delete it from the database.

AFAIK there is no “on delete cascade” code in Core and deleting fields from tables is not a supported practice, and hence not a Bug.

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [March 30, 2018, 6:38pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239/3 "2018-03-30T18:38:41Z")

</div>

> [@Mittineague](#):
>
> What other tables cross index the topic id?

I am not touching postgres. I am letting the code do its work

As per @sam at: [https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/2?u=vikaskedia](https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/2) this may nuke dependent objects.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [March 30, 2018, 6:45pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239/4 "2018-03-30T18:45:38Z")

</div>

Yes, but  
[https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/4?u=mittineague](https://meta.discourse.org/t/how-to-permanent-delete-a-topic-from-database-with-his-posts/15073/4)

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [March 30, 2018, 6:52pm UTC](https://meta.discourse.org/t/using-topic-destroy-id-to-delete-illegal-content/84239/5 "2018-03-30T18:52:05Z")

</div>

> [@Mittineague](#):
>
> but

hahaha !! that post was written in 2014 i think there might have been improvments after that ..

**Someone posted questionable content .. hence just a soft delete just does not work.**

Though I completely get @codinghorror point that there should not be hard delete in the UI. Since that creates a lot of possibilities for mischief.

Here is the code for topic.destroy [discourse/app/controllers/topics\_controller.rb at 5f19ad95074329bea3328a796f061de79db9c227 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/5f19ad95074329bea3328a796f061de79db9c227/app/controllers/topics_controller.rb#L454) this does seem to call PostDestroyer
