我知道 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"`
}
Run Code Online (Sandbox Code Playgroud)
如果我使用 gorm 多对多关联,它将创建一个锻炼锻炼连接表,但我将如何确保填写其他字段(例如次数和组数)。这是需要在控制器中完成的事情,而不是真正由 gorm 处理的事情。我已经用 Nodejs 和 Sequelize 做了类似的事情,但对于 go 和 gorm 世界来说确实是新的。