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

@@ -14,7 +14,7 @@ type User struct {
Username string `gorm:"uniqueIndex;size:255;not null"`
Password string `gorm:"not null"`
Role Role `gorm:"type:varchar(16);not null;default:'user'"`
Devices []Device `gorm:"many2many:user_devices;joinForeignKey:ID;joinReferences:GUID"`
Devices []Device `gorm:"many2many:user_devices;constraint:OnDelete:CASCADE;"`
CreatedAt time.Time
UpdatedAt time.Time
}