From a78fff889749389476c678edf9dfae51f75a42a6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 8 Dec 2024 11:46:56 +0800 Subject: [PATCH] :bug: Remove related event foreign key to prevent issue when linking to a deleted event --- pkg/internal/models/events.go | 2 -- pkg/internal/services/messages.go | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/internal/models/events.go b/pkg/internal/models/events.go index d4d6bc0..50b08c4 100644 --- a/pkg/internal/models/events.go +++ b/pkg/internal/models/events.go @@ -21,9 +21,7 @@ type Event struct { Channel Channel `json:"channel"` Sender ChannelMember `json:"sender"` QuoteEventID *uint `json:"quote_event_id,omitempty"` - QuoteEvent *Event `json:"quote_event,omitempty" gorm:"foreignKey:QuoteEventID"` RelatedEventID *uint `json:"related_event_id,omitempty"` - RelatedEvent *Event `json:"related_event,omitempty" gorm:"foreignKey:RelatedEventID"` ChannelID uint `json:"channel_id"` SenderID uint `json:"sender_id"` } diff --git a/pkg/internal/services/messages.go b/pkg/internal/services/messages.go index 57d82c9..8f1ba04 100644 --- a/pkg/internal/services/messages.go +++ b/pkg/internal/services/messages.go @@ -38,7 +38,8 @@ func EditMessage(event models.Event, body models.EventMessageBody) (models.Event } func DeleteMessage(event models.Event) (models.Event, error) { - _, err := DeleteEvent(event) + clonedEvent := event + _, err := DeleteEvent(clonedEvent) if err != nil { return event, err }