我知道 gorm 多对多关联会创建一个连接表,但是如果我想要/需要一个带有附加字段的自定义连接表怎么办
我下面的例子
所以我有两个 gorm 模型
type Exercise struct {
gorm.Model
Name string `gorm:"not null" json:"name"`
Description string `gorm:"not null json:"description"`
}
type Workout struct {
gorm.Model
Name string `gorm:"not null" json:"name"`
CreatedAt time.Time `gorm:"not null" json:"created_at"`
}
如果我使用 gorm 多对多关联,它将创建一个锻炼锻炼连接表,但我将如何确保填写诸如 reps 和 set 之类的其他字段。这是需要在控制器中完成的事情,而不是真正的 gorm 处理。我用 Nodejs 和 sequelize 做过类似的事情,但对 go 和 gorm 世界来说真的很新。
RISEBY
阿晨1998
相关分类