# ניסיון ליצור מחדש ערוץ צ'אט שנמחק באותו השם (עדיין) נכשל

**URL:** https://meta.discourse.org/t/attempt-to-recreate-deleted-chat-channel-with-the-same-name-still-fails/254747
**Category:** Bug
**Tags:** chat
**Created:** [10 בפברואר,‏ 2023,‏ 10:31am UTC](https://meta.discourse.org/t/attempt-to-recreate-deleted-chat-channel-with-the-same-name-still-fails/254747 "2023-02-10T10:31:27Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [15 בפברואר,‏ 2023,‏ 1:24am UTC](https://meta.discourse.org/t/attempt-to-recreate-deleted-chat-channel-with-the-same-name-still-fails/254747/8 "2023-02-15T01:24:56Z")

</div>

I checked and this is actually expected, since we exclude records with `deleted_at` filled in even with `find_by`:

```plaintext
ChatChannel.find_by(slug: "sec-fhir")
  ChatChannel Load (0.4ms) SELECT "chat_channels".* FROM "chat_channels" WHERE "chat_channels"."deleted_at" IS NULL AND "chat_channels"."slug" = 'sec-fhir' LIMIT 1
=> nil

```

You will need to do this instead (adding `with_deleted`):

```plaintext
ChatChannel.with_deleted.find_by(slug: "sec-fhir")
  ChatChannel Load (0.3ms) SELECT "chat_channels".* FROM "chat_channels" WHERE "chat_channels"."slug" = 'sec-fhir' LIMIT 1
=> #<CategoryChannel:0x00007fc9bfb4abf0
 id: 124,
 chatable_id: 19,
 deleted_at: Wed, 15 Feb 2023 01:19:20.982181000 UTC +00:00,
 deleted_by_id: nil,
 featured_in_category_id: nil,
 delete_after_seconds: nil,
 chatable_type: "Category",
 created_at: Fri, 13 Jan 2023 01:46:43.730329000 UTC +00:00,
 updated_at: Wed, 15 Feb 2023 01:19:56.427647000 UTC +00:00,
 name: "test channel",
 description: "",
 status: "archived",
 user_count: 1,
 last_message_sent_at: Fri, 13 Jan 2023 01:46:51.130903000 UTC +00:00,
 auto_join_users: false,
 user_count_stale: false,
 slug: "sec-fhir",
 type: "CategoryChannel",
 allow_channel_wide_mentions: true,
 messages_count: 0,
 threading_enabled: false>

```

So to clear out the old deleted channel slug do something like this:

```ruby
channel = ChatChannel.with_deleted.find_by(slug: "sec-fhir")
channel.update!(slug: "#{channel.deleted_at.strftime("%Y%m%d-%H%M")}-#{channel.slug}-deleted")

```

Maybe we need a migration to fix these @mcwumbly and @j.jaffeux ?

---

_[View the full topic](https://meta.discourse.org/t/attempt-to-recreate-deleted-chat-channel-with-the-same-name-still-fails/254747)._
