diff --git a/main_dc/yalarba/api_es/internal/database/psql_db.go b/main_dc/yalarba/api_es/internal/database/psql_db.go index 59a47a7..7f4080c 100644 --- a/main_dc/yalarba/api_es/internal/database/psql_db.go +++ b/main_dc/yalarba/api_es/internal/database/psql_db.go @@ -5,7 +5,6 @@ import ( "api_es/internal/models" "api_es/pkg/logger" "fmt" - "log" "go.uber.org/zap" "gorm.io/driver/postgres" diff --git a/main_dc/yalarba/api_es/internal/models/object.go b/main_dc/yalarba/api_es/internal/models/object.go index 202b350..207ca2b 100644 --- a/main_dc/yalarba/api_es/internal/models/object.go +++ b/main_dc/yalarba/api_es/internal/models/object.go @@ -57,8 +57,8 @@ type Object struct { ViewCount int `gorm:"default:0" json:"view_count"` // Владелец - OwnerID uint `gorm:"not null" json:"owner_id"` - Owner User `gorm:"foreignKey:OwnerID" json:"owner,omitempty"` + OwnerID uint `gorm:"not null;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"owner_id"` + Owner User `gorm:"foreignKey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"owner,omitempty"` // Связи Images []ObjectImage `gorm:"foreignKey:ObjectID" json:"images"` @@ -69,7 +69,7 @@ type Object struct { // ObjectImage представляет изображения объекта type ObjectImage struct { ID uint `gorm:"primaryKey" json:"id"` - ObjectID uint `gorm:"not null" json:"object_id"` + ObjectID uint `gorm:"not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"object_id"` URL string `gorm:"not null" json:"url"` IsPrimary bool `gorm:"default:false" json:"is_primary"` Order int `gorm:"default:0" json:"order"`