In the trackings table ClientId is not present.So after joining the tables I m getting the clientId in MySQL but when I am printing the data in golang clientId is always 0.So Please tell me how to bind that clientId with the struct?
If you can show the code that you are currently trying to use, it will be much easier to help you and I’d be more than happy to help with that info if I’m able to.
err :=DB.Select(“client.id as clientId,tracking.user_id as userId,user.name as user_name,tracking.timeslice as time”).
Table(“client”).
Joins(“left join user on user.client_id=client.id”).
Joins(“left join tracking on traking.user_id=user.id”).
Where(“client.active=1”).
Find(&track).Error
if(err!=nil){
log.Println(err);
}
fmt.Println(track);
When I am running this query in MySQL, I am getting the clientId for every row but when I am printing the track,clientId is showing 0 for all clients.Please let me know how can I get the clientId?
It’s still a bit difficult to help you since you haven’t really provided that much here, for example, what ORM are you using or what are the 2 schemas for the tables, but either way, I’m going to take a guess here.
Try using this for your Trackings struct with the following struct tags added and let me know if anything changes: