// A user has many products type User struct { // gorm.Model Id int`gorm:"primary_key;AUTO_INCREMENT"` Account string`gorm:"type:varchar(30);" json:"account"` Name string`gorm:"type:varchar(20);" json:"name"` Password string`gorm:"type:longtext;" json:"password"` Phone string`gorm:"type:varchar(10);" json:"phone"` Products []Product `json:"products"`// 有著多個 Products CreatedAt time.Time }
// Uppercase an exported to json // A product has many tags type Product struct { // gorm.Model Id int`gorm:"primary_key;AUTO_INCREMENT"` ProductName string`gorm:"type:varchar(50);" json:"productName"` Price string`gorm:"type:int;" json:"price"` PurchaseDate string`json:"purchaseDate"` UserId int`gorm:"foreign_key" sql:"index" json:"userId"` Tags []Tag `json:"tags"`// 有著多個 Tags CreatedAt time.Time DeletedAt *time.Time }
type Tag struct { // gorm.Model Id int`gorm:"primary_key;AUTO_INCREMENT"` Name string`gorm:"type:varchar(10);" json:"name"` ProductId int`gorm:"foreign_key" sql:"index" json:"productId"` UserId int`gorm:"foreign_key" sql:"index" json:"userId"` DeletedAt *time.Time }
type Auths struct { Id int`gorm:"primary_key;AUTO_INCREMENT"` UserId int`gorm:";not null;" json:"userId"` AuthUuid string`gorm:"size:255;not null;" json:"auth_uuid"` }