i have a contacts relation to provinces, and here is on my struct
Contact struct {
tableName struct{} `pg:"contacts,discard_unknown_columns"`
ID int `json:"id"`
Address string `json:"address"`
BuildingType string `json:"building_type"`
BuildingNumber float64 `json:"building_number"`
Province *Province `pg:"fk:province_id" json:"province"`
}
Province struct {
tableName struct{} `pg:"provinces,discard_unknown_columns"`
ID int `json:"id" pg:",pk"`
Name string `json:"name"`
}
and here how i call:
var us Contact
err = db.Model(&us).Relation("provinces").Where(
"id = ?", 3,
).Select()
what i go is model=Contact does not have relation="provinces"
how to correct way to query this with go-pg?
when i change tag on Contact for Province with tag pg:"rel:has-one"
i got this error
pg: Contact has-one Province: Contact must have column province_id (use fk:custom_column tag on Province field to specify custom column)
note: i dont use their migration, i use sql-migration for all migrations
Your province is missing a foreign key, try this I think it will work.