我有两个结构来表示一个ManyToMany关系。用户和备注
type User struct {
ID int
Name string
Notes []*Note
}
type Note struct {
TableName struct{} `sql:"user_notes"`
ID int
Text string
}现在假设我想要插入一个新用户,同时添加一些注释。
我希望这会插入一个用户及其备注:
note := Note{
Text: "alohaa dude",
}
user := User{
Name: "peter",
Notes: []Note{no},
}
s.DB.Insert(&user)但是,这只会保存用户,而不会保存用户和注释。在go-pg中,我是必须手动完成这项工作,还是有一种自动完成ORM的方法?
发布于 2017-07-08 23:47:39
罗德里戈,同样的问题陈述也在这里讨论:https://github.com/go-pg/pg/issues/478
go-pg目前不支持此功能,您可能希望尝试使用数据库准备方法来插入with关系。
https://stackoverflow.com/questions/41541267
复制相似问题