Files
smartride-backend-golang/models/classname.go
2024-11-11 10:57:15 +08:00

21 lines
611 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package models
import (
"github.com/google/uuid"
"gorm.io/gorm"
)
// Classname 班级表
type Classname struct {
ID string `gorm:"type:uuid;primaryKey" json:"id"`
Name string `gorm:"type:varchar(255);not null" json:"name"`
Campus string `gorm:"type:varchar(255);not null" json:"campus"` // 教学楼所属校区名称
CampusID string `gorm:"type:uuid;not null" json:"campus_id"` // 教学楼所属校区ID外键
}
// BeforeCreate 在创建Classname之前生成UUID
func (classname *Classname) BeforeCreate(tx *gorm.DB) (err error) {
classname.ID = uuid.New().String()
return
}