Gorm学习小记

Gorm学习手册:http://gorm.book.jasperxu.com/
Go学习中文网提供手册: https://books.studygolang.com/gorm/

1、模型结构体字段设置标签注意点:
* tag(如:gorm、json form)后面的冒号与双引号之间不能有空格;
* 同一种tag,不同属性定义使用“;”分隔;不同tag 使用空格“ ”分隔;
* 使用预加载Preload,需要在结构体中指明外键(不指名则默认是预加载表的主键作为外键)

type CheckResult struct {
	Id          uint   `gorm:"primary_key;auto_increment" json:"id"`
	WebId       uint   `gorm:"not null;"`
	ServerId    uint   `gorm:"not null;"`
	CheckInfo   []byte `gorm:"not null;"`
	CheckStatus uint   `gorm:"not null;default:1;"`
	CreateTime  uint   `gorm:"not null;"`
	UpdateTime  uint   `gorm:"not null;"`
	Web         Web
	Server      Server
}

原文地址:https://www.cnblogs.com/xinxinmifan/p/golang_gorm_learning_notes.html