I’m facing a problem with deleting ModelA
along with its associated ModelB
instances using Gorm’s soft delete methods. Here’s a simplified version of my code:
type ModelA struct {
gorm.Model
ModelAID uint
// Association
ModelBs []ModelB `gorm:"foreignKey:ModelAID"`
}
type ModelB struct {
gorm.Model
ModelA_ID uint
ModelA ModelA `gorm:"foreignKey:ModelAID"`
}
And this is how I attempted to delete ModelA
and its associations:
db.Select(clause.Associations).Delete(&gcs_models.GcsAcademicYear{}, request.ID)
Unfortunately, this approach doesn’t seem to work as expected. Any insights or suggestions on how to properly delete both ModelA
and its associated ModelB
instances using Gorm’s soft delete methods would be greatly appreciated.