I'm trying to get the name of platforms based on games id.
I have three tables as below and I'm trying to JOIN them to get result that needed:
Games
Id | .....| .....|
---|------ ------|
1 | . | . |
2 | . | . |
3 | . | . |
4 | . | . |
Game_Platforms
Id |....|game_id| platform_id|...|
---------------------------------
1 | . | 1 | 1 |.. |
2 | . | 1 | 2 |.. |
3 | . | 3 | 3 |.. |
.. | . | 4 | 4 |.. |
Platforms
Id| ...|...| name |
---------------------|
1 | . | . | iOS |
2 | . | . | Android |
3 | . | . | Windows |
4 | . | . | SteamOS |
type Platforms struct {
Name string
}
var name []Platforms
query = postgres.Db().Select("name").
Joins("JOIN games ON games.id = game_platforms.game_id").
Joins("JOIN game_platforms ON game_platforms.platform_id = platforms.id").
Where("games.id = 1").Find(&name)
I expect to get the Platforms name, but get the error:
pq: missing FROM-clause entry for table "game_platforms"
I think that I wrote Joins commands incorrect, but it seems logical, maybe I'm wrong.