Golang 入门资料+笔记

gorm预加载映射

2021-03-19  本文已影响0人  五岁小孩

gorm预加载映射

代码

type Class struct{
    Id int `json:"id";gorm:"column:class_id;type:int(11);not null"`
    ClassName string `json:"class_name";gorm:"column:class_name;type:varchar(255);not null"`
}
type Student struct{
    StuId int `json:"stu_id";gorm:"column:stu_id;type:int(11);not null"`
    ClassId int `json:"class_id";gorm:"column:class_id;type:int(11);not null"`
    StuName string `json:"stu_name";gorm:"column:stu_name;type:varchar(255);not null"`
    //关联对象  ForeignKey为关联对象(Class),AssociationForeignKey为当前对象(Student)
    Class Class `json:"Class";gorm:"ForeignKey:Id;AssociationForeignKey:ClassId"`
}
上一篇 下一篇

猜你喜欢

热点阅读