[Beego模型] 一、ORM 使用方法
[Beego模型] 一、ORM 使用方法 [Beego模型] 二、CRUD 操作 [Beego模型] 三、高级查询 [Beego模型] 四、使用SQL语句进行查询 [Beego模型] 五、构造查询 [Beego模型] 六、事务处理 beego/orm 的使用例子 后文例子如无特殊说明都以这个为基础。 models.go: package main import ( "github.com/astaxie/beego/orm" ) type User struct { Id int Name string 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