我们目前有以下模式;
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"`
}当尝试使用以下查询查询所有帖子(包括它们的反应关系)时,我们会收到以下错误消息: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()
}实际上,我对这个问题非常困惑,就好像我们用Relation("Reaction.type")替换为Relation("Reaction.*")一样,我们没有得到错误(尽管Creator和Post都是null),但是我们检索的列比我们想要的多。
发布于 2022-09-27 16:16:45
我不是一个专业的,但这不是反应在邮政模式。它应该是Reactions Reaction ...而不是Reactions Reactions ...。因为模型是反应而不是反应。我希望它能解决这个问题,我不是个傻瓜。
https://stackoverflow.com/questions/73870024
复制相似问题