For a simple model with a self-referential many2many link (Depends) an Updates() does not remove associations.
It seems that a db.Model(self3).Association("Depends").Replace(self3.Depends)
should be implicit in FullSaveAssociations
type Self struct {
gorm.Model
Name string
Depends []*Self `gorm:"many2many:self_depends"`
}
self3.Depends = []*Self{self1}
// saves with 1 insert into self_depends
db.Session(&gorm.Session{FullSaveAssociations: true}).Updates(self3)
self3.Depends = []*Self{self1, self2}
// saves with 2 inserts into self_depends.
db.Session(&gorm.Session{FullSaveAssociations: true}).Updates(self3)
self3.Depends = []*Self{self1}
// saves with 1 insert into self_depends but no removals
db.Session(&gorm.Session{FullSaveAssociations: true}).Select("*", clause.Associations).Updates(self3)
// at this point a read of self3 will show self3.Depends == []*Self{self1, self2}
Full minimal example
https://go.dev/play/p/KIC86xOJZVN or https://gist.github.com/lbt-bd/ec87648d0fe3d4b8bea3c3073eb087dd
The go-gorm/playground doesn't work on MacOS
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨