Golang Gorm: Is it possible to delete a record via a many2many relationship?

后端 未结 3 2152
不知归路
不知归路 2021-02-20 14:31

I have a many2many structure similar to GORM\'s example:

// User has and belongs to many languages, use `user_languages` as join table
type User struct {
    gor         


        
3条回答
  •  故里飘歌
    2021-02-20 14:51

    I was having the same problem, If you want to just remove one of the associations this worked for me

        c.DB.Model(&user).Association("Roles").Delete(&role)
    

提交回复
热议问题