Your Question
type User struct {
Id int gorm:"primaryKey;autoIncrement;" json:"Id"
Name string json:"name"
Roles []Rolegorm:"many2many:user_role;"
...
}
type Role struct {
Id int gorm:"primaryKey;autoIncrement;" json:"Id"
Name string json:"name"
...
}
user := User{Name:"test", Roles:[]Role{
{Name:"角色名称1"},
{Name:"角色名称2"},
}}
user_role table fields (user_id, role_id, sort)
Now only the role of the intermediate table will be updated_ Id and user_ id . How to update the middle table field sort ?
The document you expected this should be explained
The document link you expected this question should be explained in our official documents site
Expected answer
Expected to update the sorting of other fields in the intermediate table