type User struct { Id int64 `json:"id" ` Name string `json:"name,omitempty" orm:"size(50)"` Passwords string `json:"passwords" orm:"size(32)"` Baby []*Baby `json:"baby" orm:"reverse(many)"` } type Baby struct { Id int64 Name string `json:"name" orm:"size(50)"` User *User `json:"user" orm:"rel(fk);index"` }
Baby表
数据库操作
o:= orm.NewOrm() o.QueryTable("tb_user").Filter("id" ,user.Id).One(user) o.LoadRelated(user,"Baby")
{ "id": 2, "name"