fixed gorm shema for correct deletion and many2many relation beetween users and devices

This commit is contained in:
tdv
2025-09-15 16:59:35 +03:00
parent 673971deb8
commit aa60651610
5 changed files with 17 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ import "time"
type Device struct {
GUID string `gorm:"primaryKey"`
Name string `gorm:"size:255;not null"`
Users []User `gorm:"many2many:user_devices;joinForeignKey:ID;joinReferences:GUID"`
Users []User `gorm:"many2many:user_devices;constraint:OnDelete:CASCADE;"`
Records []Record `gorm:"foreignKey:DeviceGUID;references:GUID;constraint:OnDelete:CASCADE"`
CreatedAt time.Time
UpdatedAt time.Time