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/internal/models"
|
||||||
"api_es/pkg/logger"
|
"api_es/pkg/logger"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ type Object struct {
|
|||||||
ViewCount int `gorm:"default:0" json:"view_count"`
|
ViewCount int `gorm:"default:0" json:"view_count"`
|
||||||
|
|
||||||
// Владелец
|
// Владелец
|
||||||
OwnerID uint `gorm:"not null" json:"owner_id"`
|
OwnerID uint `gorm:"not null;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"owner_id"`
|
||||||
Owner User `gorm:"foreignKey:OwnerID" json:"owner,omitempty"`
|
Owner User `gorm:"foreignKey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"owner,omitempty"`
|
||||||
|
|
||||||
// Связи
|
// Связи
|
||||||
Images []ObjectImage `gorm:"foreignKey:ObjectID" json:"images"`
|
Images []ObjectImage `gorm:"foreignKey:ObjectID" json:"images"`
|
||||||
@@ -69,7 +69,7 @@ type Object struct {
|
|||||||
// ObjectImage представляет изображения объекта
|
// ObjectImage представляет изображения объекта
|
||||||
type ObjectImage struct {
|
type ObjectImage struct {
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
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"`
|
URL string `gorm:"not null" json:"url"`
|
||||||
IsPrimary bool `gorm:"default:false" json:"is_primary"`
|
IsPrimary bool `gorm:"default:false" json:"is_primary"`
|
||||||
Order int `gorm:"default:0" json:"order"`
|
Order int `gorm:"default:0" json:"order"`
|
||||||
|
|||||||
Reference in New Issue
Block a user