# A post's TopicEmbed isn't destroyed when the post is deleted

**URL:** https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904
**Category:** Development
**Created:** [4월 13, 2017, 8:32오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904 "2017-04-13T08:32:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [4월 13, 2017, 8:32오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/1 "2017-04-13T08:32:40Z")

</div>

When a post is created through the API with an `embed_url` property, the `TopidEmbed` that’s created on Discourse isn’t being destroyed when the topic is deleted. I don’t know if this is by accident or by design.

The problem I’m having with it is that it makes it hard to setup any integration tests between the wp-discourse plugin and Discourse. Every time the tests are run, the `TopicEmbeds` that are created by the tests have to be deleted through the rails console.

It also creates a small problem for general use of the plugin. If a post on Discourse that has been created through the wp-discourse plugin is ever deleted, the only way to republish it from WordPress is to go to the rails console and delete the `TopicEmbed` that is associated with the post.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [4월 13, 2017, 8:53오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/2 "2017-04-13T08:53:05Z")

</div>

How are you fetching topic embeds? Maybe adding a scope like `where("topics.deleted_at IS NULL && posts.deleted_at IS NULL)` will help?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [4월 13, 2017, 9:11오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/3 "2017-04-13T09:11:22Z")

</div>

> [@tgxworld](#):
>
> How are you fetching topic embeds?

I’m not fetching them, the `embed_url` is sent as a property when a post is published on Discourse through the wp-discourse plugin. The post can’t be created if the `embed_url` already exists because `TopicEmbed` validates the uniqueness of `embed_url`.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [4월 18, 2017, 8:38오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/4 "2017-04-18T08:38:50Z")

</div>

I think we need to make `TopicEmbed` trashable as well. I’m not too farmiliar with what `TopicEmbed` is used for though so maybe someone else from [@team](https://meta.discourse.org/groups/team) can assist.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [4월 18, 2017, 8:53오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/5 "2017-04-18T08:53:25Z")

</div>

I have worked a bit on [topic embedding](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963), added on my list. ✏

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [4월 25, 2017, 2:44오후 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/6 "2017-04-25T14:44:27Z")

</div>

> [@tgxworld](#):
>
> I think we need to make TopicEmbed trashable as well.

This is now done via:

[https://github.com/discourse/discourse/commit/aeead600363b8e80d75bbff0bdca2234064d895e](https://github.com/discourse/discourse/commit/aeead600363b8e80d75bbff0bdca2234064d895e)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [4월 28, 2017, 10:00오전 UTC](https://meta.discourse.org/t/a-posts-topicembed-isnt-destroyed-when-the-post-is-deleted/60904/7 "2017-04-28T10:00:22Z")

</div>

This topic was automatically closed after 36 hours. New replies are no longer allowed.
