我使用 GORM 中的 has many。以下是我的模型:
type Pro struct {
Model
TaxRate []TaxRate `json:"taxRate" gorm:"constraint:OnUpdate:CASCADE;"`
}
type TaxRate struct {
ID uint
Tax float64
ProjectID uint
}
但是当我更新项目时,我发现TaxRate只插入记录而不是更新。这是我的更新操作:
result:=pRepo.db.Session(&gorm.Session{FullSaveAssociations: true}).Updates(p)