You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
979 B
Go

9 months ago
package models
// type User struct {
// Id int `form:"-"`
// Name interface{} `form:"username"`
// Age int `form:"age"`
// Email string `form:"email"`
// }
type User struct {
Id int
Name string
Age int `form:"age"`
Email string `form:"email"`
Profile *Profile `orm:"rel(one)"` // OneToOne relation
Post []*Post `orm:"reverse(many)"` // 设置一对多的反向关系
}
type Profile struct {
Id int
Age int16
User *User `orm:"reverse(one)"` // 设置一对一反向关系(可选)
}
type Post struct {
Id int
Title string
User *User `orm:"rel(fk)"` //设置一对多关系
Tags []*Tag `orm:"rel(m2m)"`
}
type Tag struct {
Id int
Name string
Posts []*Post `orm:"reverse(many)"` //设置多对多反向关系
}
// func init() {
// // 需要在init中注册定义的model
// orm.RegisterModel(new(User), new(Post), new(Profile), new(Tag))
// orm.RunSyncdb("default", false, true)
// }