我找不到我的问题的答案。我在 golang 项目中使用 jinzhu/gorm :) 我有以下结构:type Catalog struct { ID int64 `gorm:"primary_key" form:"id"` SubDomainID int64 `form:"sub_domain_id"` ServiceTypeID int64 `form:"service_type_id"` Checked bool `form:"checked"` CreatedAt time.Time `form:"created_at"` UpdatedAt time.Time `form:"updated_at"` SubDomain SubDomain}type SubDomain struct { Id int64 `gorm:"primary_key" form:"id"` NameRu string `form:name_ru` url string `form:url`}当我尝试通过预加载子域获取目录时:var catalog Catalogfmt.Println(catalog.SubDomain)err := db.Preload("SubDomain").Where("checked = 0").First(&catalog).Errorif err != nil { return &catalog, err}我收到以下错误: can't find field SubDomain in *models.Catalog为什么会这样?我预计会有 2 个查询:select * from catalogs where checked = 0;select * from sub_domains where id = (catalog.sub_domain_id)
1 回答
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消