【发布时间】:2019-03-28 10:46:51
【问题描述】:
假设我有两个表,它们共享一些列名,例如:
table_1
- id
- created_at
- deleted_at
- name
- color
table_2
- id
- created_at
- deleted_at
- address
- name
当我在这两个表上运行连接查询时,我会得到这样的结果:
id, created_at, name, color, id, created_at, deleted_at, address, name
我有 2 个类似于我上面描述的模型的结构。现在我想将结果扫描到一个结果结构中:
type Result struct {
Model1
Model2
}
然后我使用db.Raw().Scan(&result)。现在的问题:
table_2 的 id 永远不会写入表 2 的结构中,只会写入结果结构中的表 1 的结构中。
我的问题是:当存在同名的列时,如何将 JOIN 查询的结果读入结果结构中。
【问题讨论】:
-
你解决过这个问题吗?