我正在开发bun,它有一个在PostgreSQL中运行的数据库。这两张表之间是有关系的。Order和ResPartner,其中Order表具有具有列名contact_partner的ResPartner表的外键
type Order struct {
bun.BaseModel `bun:"select:sb_order"`
ID int64 `bun:"id"`
GenOid string `bun:"gen_oid"`
ContactPartner *ResPartner `bun:"rel:belongs-to"`
ContactPartnerID int64 `bun:"contact_partner"`
}type ResPartner struct {
bun.BaseModel `bun:"select:sb_partner"`
ID int64 `bun:"id"`
Name string `bun:"name"`
}我试着提出这样的疑问。
err = db.NewSelect().Model(&order).
Relation("ContactPartner").
Scan(ctx)但它是错误的。
reflect: call of reflect.Value.Field on ptr Value
我想bun想找一个像contact_partner_id这样的字段名。有什么方法可以重写字段名吗?
更新:我更新了我的问题。参见这个回购,例如:转分贝测试
发布于 2021-12-21 07:56:10
你可以在bun中映射关系:比如:
属于-属于:
type User struct {
ID int64 `bun:",pk"`
Name string
ProfileID int64
Profile *Profile `bun:"rel:belongs-to,join:profile_id=id"`
}有-一个:
type User struct {
ID int64 `bun:",pk"`
Name string
Profile *Profile `bun:"rel:has-one,join:id=user_id"`
}https://stackoverflow.com/questions/69394675
复制相似问题