[TOC] ## 一对多 ``` type HsUser struct { UserId int `orm:"pk"` UserLogin string UserName string UserSex int HsUserConfig []*HsUserConfig `orm:"reverse(many)"` } type HsUserConfig struct { CfgId string `orm:"pk;"` //UserId int `orm:"-"` //注意不需要此字段,映射rel时自动包含了此字段 CfgDataType string HsUser *HsUser `orm:"rel(fk);column(user_id)"` } ``` ## 查 ``` o := orm.NewOrm() //通过 user_id 找多条 hsUserConfig hsUserConfig := new([]HsUserConfig) num, err := o.QueryTable("hs_user_config").Filter("user_id", 107).All(hsUserConfig) ThrowErr(err) fmt.Println(num) fmt.Println(hsUserConfig) //通过一条 hsUserConfig的条件 查到对应的user_id user := new(HsUser) o.QueryTable(user).Filter("HsUserConfig__CfgDataType", "contact1").RelatedSel().Limit(1).One(user) //注意 CfgDataType 需要在struct 中 fmt.Println(user) ```