Go Gorm: 指定关联表名
在使用 Go Gorm 库进行关联查询时,如果您需要指定关联表名,可以使用以下方法:
db.Preload("CustomOrders", "table_name = 'custom_orders'").Find(&companies)
其中,CustomOrders 是关联的结构体名称,table_name = 'custom_orders' 是指定关联的表名为 custom_orders。
通过这种方式,您可以根据实际情况灵活指定关联表名。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/lWVu 著作权归作者所有。请勿转载和采集!