# 通过 Rails 完全删除数百个主题的正确方法？

**URL:** <https://meta.discourse.org/t/the-proper-way-to-completely-delete-hundred-of-topics-via-rails/90323>\
**Category:** Support\
**Created:** [2018年六月20日 15:52 UTC](https://meta.discourse.org/t/the-proper-way-to-completely-delete-hundred-of-topics-via-rails/90323 "2018-06-20T15:52:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年六月21日 10:28 UTC](https://meta.discourse.org/t/the-proper-way-to-completely-delete-hundred-of-topics-via-rails/90323/5 "2018-06-21T10:28:07Z")

</div>

Interesting… we are missing a dependant destroy here, I am not sure why.

> <https://github.com/discourse/discourse/blob/main/app/models/topic.rb#L119>

Easy to fix though

```ruby
Post.where('topic_id not in (select id from topics)').limit(100).destroy_all

```

And repeat… till no results.

---

_[View the full topic](https://meta.discourse.org/t/the-proper-way-to-completely-delete-hundred-of-topics-via-rails/90323)._
