【发布时间】:2020-09-26 12:15:39
【问题描述】:
在 golang 中使用 gorm,我有 2 个模型:Shipment 和 Customer
基本上在 Shipment 模型上,我有一个对应于客户 ID 的 int。 但是在客户方面,我没有将其与 Shipments 链接的字段。
这是我的模型:
type Shipment struct {
ID int64 `json:"id"`
Customer Customer `json:"customer"`
}
type Customer struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
在数据库中,我有:
map_shipment (table name)
id, customer_id
map_customer (table name)
id, name
这是我当前使用的请求。
db.Table("map_shipment").Preload(clause.Associations).Find(&shipments)
如何防止 gorm 在 Customer 上查找 ShipmentId 字段?
【问题讨论】:
标签: sql postgresql go go-gorm