99// University model
1010type University struct {
1111 gorm.Model
12- Name string `gorm:"type:varchar(200);unique; not null"`
12+ Name string `gorm:"type:varchar(200);not null"`
1313 Location string `gorm:"type:varchar(100);not null"`
1414 EstablishedDate time.Time `gorm:"type:date"`
1515 Departments []Department // One-to-Many relationship: A University has many Departments
@@ -18,22 +18,22 @@ type University struct {
1818// Department model
1919type Department struct {
2020 gorm.Model
21- Name string `gorm:"type:varchar(100);unique;not null"`
22- HeadOfDepartment string `gorm:"type:varchar(100)"`
23- UniversityID uint `gorm:"not null"`
21+ Name string `gorm:"type:varchar(100);unique;not null"`
22+ HeadOfDepartment string `gorm:"type:varchar(100)"`
23+ UniversityID uint
2424 University University `gorm:"constraint:OnDelete:CASCADE"`
2525 Students []Student // One-to-Many relationship: A Department has many Students
2626}
2727
2828// Student model
2929type Student struct {
3030 gorm.Model
31- FirstName string `gorm:"type:varchar(50);not null"`
32- LastName string `gorm:"type:varchar(50);not null"`
33- StudentIDNumber string `gorm:"type:varchar(20);unique;not null"`
34- DateOfBirth time.Time `gorm:"type:date"`
35- Email string `gorm:"type:varchar(255);unique;not null"`
36- EnrollmentDate time.Time `gorm:"autoCreateTime;type:date"`
37- DepartmentID * uint
31+ FirstName string `gorm:"type:varchar(50);not null"`
32+ LastName string `gorm:"type:varchar(50);not null"`
33+ StudentIDNumber string `gorm:"type:varchar(20);unique;not null"`
34+ DateOfBirth time.Time `gorm:"type:date"`
35+ Email string `gorm:"type:varchar(255);unique;not null"`
36+ EnrollmentDate time.Time `gorm:"autoCreateTime;type:date"`
37+ DepartmentID * uint `gorm:"column:department_link"`
3838 Department * Department `gorm:"constraint:OnDelete:SET NULL;"` // Belongs-to relationship, SET NULL on delete
3939}
0 commit comments