Suppose I have 2 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 theres 2 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.
I hope I described my problem clearly enough. My question is: How can I read the results of a JOIN query into a results struct, when there are columns named the same.
</div>