Search code examples
postgresqlgogo-pg

Ambiguous column reference when joining


Structs

type Client struct {
   Id int64
   Name string
}

type Trade struct {
   Id int64
   ClientId int64
   Client *Client
}

Query db.Model(&Trade).Where("id = ", tradeId).Relation("Client").Select()

Error encountered: Column Id ambiguous. Not sure what's the proper way to work around this Would be great if someone can help


Solution

  • You may try qualifying the Id column with either an alias or the full table name, e.g.

    db.Model(&Trade).Where(`"Trade".id = ?`, tradeId).Relation("Client").Select()