type Student struct {
ID string
ClassId string
Class Class
Name string
Teachers []Teacher `gorm:"many2many:stu_tea"`
}
//一对多关系:一个班级中有多个学生
type Class struct {
ID int
ABC int
Students []Student `gorm:"FOREIGNKEY:ClassId;ASSOCIATION_FOREIGNKEY:Name;references:ABC"`
}
目前只知道
FOREIGNKEY:指定外表字段,作为外键关联主表主键
REFERENCES:指定当前表字段,代替主键被外键关联
ASSOCIATION_FOREIGNKEY保留疑问,测试不出来