feat: many-to-one check, constrints check

This commit is contained in:
2025-03-17 13:13:35 +07:00
parent 4b5580b1c8
commit 60e0a64a24
6 changed files with 168 additions and 18 deletions

View File

@@ -2,20 +2,39 @@ package relations_check
type Student struct {
Id uint `gorm:"primaryKey"`
Courses []Course `gorm:"many2many:student_courses;"`
Courses []Course `gorm:"many2many:student_courses;constraint:OnDelete:CASCADE;"`
}
type Course struct {
Id uint `gorm:"primaryKey"`
Students []Course `gorm:"many2many:student_courses;"` // want "Invalid type `Course` in M2M relation \\(use \\[\\]\\*Student or self-reference\\)"
Students []Course `gorm:"many2many:student_courses;constraint:OnDelete:CASCADE"` // want "Invalid type `Course` in M2M relation \\(use \\[\\]\\*Student or self-reference\\)"
}
type Author struct {
Id uint `gorm:"primaryKey"`
Articles []Article `gorm:"many2many:author_articles;"`
Articles []Article `gorm:"many2many:author_articles;constraint:OnDelete:CASCADES;"`
}
type Article struct {
Id uint `gorm:"primaryKey"`
Authors Author `gorm:"many2many:author_articles;"` // want "M2M relation `author_articles` with bad type `Author` \\(should be a slice\\)"
Authors Author `gorm:"many2many:author_articles;constraint:OnDelete:CASCADE;"` // want "M2M relation `author_articles` with bad type `Author` \\(should be a slice\\)"
}
type Kuzbass struct {
Id uint `gorm:"primaryKey"`
Cities []City // want "Expected foreignKey `KuzbassId` in model `City` for 1:M relation with model `Kuzbass`"
}
type City struct {
Id uint `gorm:"primaryKey"`
Kuzbass Kuzbass
}
type Federation struct {
Lands []Land `gorm:"constraint:OnDelete:CASCADE;"` // want ""
}
type Land struct {
Id uint `gorm:"primaryKey"`
FederationId uint
}