modified: main_dc/yalarba/api_es/internal/database/psql_db.go
modified: main_dc/yalarba/api_es/internal/models/object.go add constrains and fix bag with import
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"api_es/internal/models"
|
||||
"api_es/pkg/logger"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/driver/postgres"
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user