Postgresql go pg-pg:找不到型号id=“,”的dst值
正在获取pg:找不到模型id=、的dst值 我定义了以下模型Postgresql go pg-pg:找不到型号id=“,”的dst值,postgresql,go,orm,go-pg,Postgresql,Go,Orm,Go Pg,正在获取pg:找不到模型id=、的dst值 我定义了以下模型 // omitting fields which don't seem relevant to the issue // corresponding queries also shortened as appropriate type GrProduct struct { tableName struct{} `sql:"gr_product"` ID int64 Na
// omitting fields which don't seem relevant to the issue
// corresponding queries also shortened as appropriate
type GrProduct struct {
tableName struct{} `sql:"gr_product"`
ID int64
Name string
// fk:Product,joinFK:Category given so that joins are made on category_id and product_id with gr_product_category_mapping
Categories []*GrCategory `pg:",many2many:gr_product_category_mapping,fk:Product,joinFK:Category"`
CategoryMappings []*GrProductCategoryMapping `pg:",fk:Product"`
}
type GrProductCategoryMapping struct {
tableName struct{} `sql:"gr_product_category_mapping"`
ID int64
ProductID int64 // product_id in db instead of gr_product_id
CategoryID int // category id in db instead of gr_category_id
IsPrimary bool
}
type GrCategory struct {
tableName struct{} `sql:"gr_category"`
ID int
Name string
Products []*GrProduct `pg:",many2many:gr_product_category_mapping,fk:Category,joinFK:Product"`
}
试一试这个——
p := models.GrProduct{}
if err := models.DB.Model(&p).
Column("Categories").
Where("id = ?", 10).
Select(); err != nil {
panic(err)
}
这些是所做的查询
SELECT
"gr_product"."id",
"gr_product"."name"
FROM
gr_product AS "gr_product"
WHERE
(
id= 10
);
SELECT
gr_product_category_mapping.*,
"gr_category"."id",
"gr_category"."name"
FROM
gr_category AS "gr_category"
JOIN
gr_product_category_mapping AS gr_product_category_mapping
ON (
gr_product_category_mapping."product_id"
) IN (
(
10
)
)
WHERE
(
"gr_category"."id" = gr_product_category_mapping."category_id"
);
我感到恐慌:pg:我想在网上找不到model id=的dst值。
在尝试使用delve进行深入挖掘时,我发现'prefix'm.baseTable.ModelName+u的计算结果为gr_product_u,但可能应该是product_u,因为列包含
我还没有弄清楚如何覆盖这个默认行为。对于Golang和go pg来说都是新的,如果您能提供任何帮助,我们将不胜感激,谢谢您应该能够使用sql标记覆盖默认的列名
type GrProductCategoryMapping struct {
tableName struct{} `sql:"gr_product_category_mapping"`
ID int64
ProductID int64 `sql:"product_id"`
CategoryID int `sql:"category_id"`
IsPrimary bool
}
阅读更多信息。这是一个在v6.4.6中修复的错误。
以下是相关问题-我会尝试一下并让您知道,但ProductID是否已经代表product_id-*更新:这没有帮助您是对的,这不会解决您的问题,我应该更仔细地阅读问题。
type GrProductCategoryMapping struct {
tableName struct{} `sql:"gr_product_category_mapping"`
ID int64
ProductID int64 `sql:"product_id"`
CategoryID int `sql:"category_id"`
IsPrimary bool
}