feat: foreignKeys check

+fix: "unnamed" field bug
This commit is contained in:
2024-12-30 23:44:24 +07:00
parent ece3f3c801
commit 03ccaff375
10 changed files with 123 additions and 21 deletions

View File

@@ -0,0 +1,12 @@
package foreign_key_check
type User struct {
Name string
CompanyRefer uint
Company Company `gorm:"foreignKey:CompanyRefer"`
}
type Company struct {
ID int
Name string
}

View File

@@ -0,0 +1,27 @@
package foreign_key_check
type PrepTask struct {
Id uint `gorm:"primaryKey"`
Description string
TaskId uint
WorkAreaId uint
WorkArea `gorm:"foreignKey:WorkAreaIds;constraint:OnDelete:CASCADE;"` // want "Foreign key \"WorkAreaIds\" mentioned in tag at field \"WorkArea\" doesn't exist in model \"PrepTask\""
Deadline int64
}
type WorkArea struct {
Id uint `gorm:"primaryKey"`
Name string
Description string
Performance uint
PrepTasks []PrepTask `gorm:"constraint:OnDelete:CASCADE;"`
}
type Shift struct {
Id uint `gorm:"primaryKey"`
Description string
ProductAmount uint
ShiftDate int64
WorkAreaId string // want "Foreign key should have type like int, not \"string\""
WorkArea WorkArea `gorm:"foreignKey:WorkAreaId;"`
}