Suppose I have two tables, which share some column names such as:
table_1
- id
- created_at
- deleted_at
- name
- color
table_2
- id
- created_at
- deleted_at
- address
- name
When I run a join query on these two tables I get something back like this:
id, created_at, name, color, id, created_at, deleted_at, address, name
I have 2 structs resembling the models I described above. Now I want to scan the results into a results struct:
type Result struct {
Model1
Model2
}
I then use db.Raw().Scan(&result). Now the Problem:
The id of table_2 is never written into the struct for table 2, only into the struct of table 1 in the results struct.
My question is: how can I read the results of a JOIN query into a results struct, when there are columns named the same.