We currently have the following schema;
type Reactions []*Reaction
type Post struct {
ID string `pg:",pk" json:",omitempty"`
CreatorID string `pg:",notnull"`
Creator *User `pg:",rel:has-one,fk:creator_id"`
Groups Groups
Reactions Reactions `pg:",rel:has-many" json:",omitempty"`
}
type Reaction struct {
ID string `pg:",pk" json:",omitempty"`
Type ReactionType `pg:",notnull"`
CreatorID string `pg:",notnull"`
Creator *User `pg:",rel:has-one,fk:creator_id"`
PostID string `pg:",notnull"`
Post *Post `pg:",rel:has-one,fk:post_id"`
}
When trying to query all Posts including their Reaction Relations using the following query, we recieve the following error message; pg: relation=\"Reactions\" does not have base model=Post with id=\"\" (check join conditions)
func (pm PGPostRepo) selectQuery(model ...interface{}) *orm.Query {
return pm.db.Model(model...).
Relation("Creator.id").
Relation("Creator.given_name").
Relation("Creator.family_name").
Relation("Reactions.type").
Column("post.*")
Where("post.id = ?", postID).
Select()
}
I'm actually quite lost on this one, as if we replace
Relation("Reaction.type") with Relation("Reaction.*") we do not get the error(Though both Creator & Post are null), but then we're retrieving more columns than we'd like.
I am not a pro but isn't it the Reactions in Post model. It should be
Reactions Reaction ...instead ofReactions Reactions .... Because the model is Reaction, not Reactions. I hope it solves the problem and i am not a stupid.