From 5fb2c69c2b3cc439b6895d9bfb5ff387e4b1ca6b Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Sat, 20 Jul 2024 17:55:31 +0200 Subject: [PATCH] fix: remove codeHostings when deleting publishers (#250) Remove the associated codeHostings when using DELETE on a publisher. Code hostings are mapped 1-to-1 with a publisher, so they they're part of the resource. Not deleting them means we'd have dangling code hosting with no publisher, invisible to the API, and that can't be associated to a publisher anymore. --- internal/models/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/models/models.go b/internal/models/models.go index 8548480..eef03be 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -35,7 +35,7 @@ type Publisher struct { ID string `json:"id" gorm:"primaryKey"` Email *string `json:"email,omitempty"` Description string `json:"description" gorm:"uniqueIndex;not null"` - CodeHosting []CodeHosting `json:"codeHosting" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;unique"` + CodeHosting []CodeHosting `json:"codeHosting" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;unique"` Active *bool `json:"active" gorm:"default:true;not null"` AlternativeID *string `json:"alternativeId,omitempty" gorm:"uniqueIndex"` CreatedAt time.Time `json:"createdAt" gorm:"index"`