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"`
}
网友评论