This commit is contained in:
black 2023-04-23 17:22:24 +08:00
parent 1bfa31fa7f
commit 59d4c98621

View File

@ -98,6 +98,7 @@ func (association *Association) Replace(values ...interface{}) error {
for _, ref := range rel.References { for _, ref := range rel.References {
updateMap[ref.ForeignKey.DBName] = nil updateMap[ref.ForeignKey.DBName] = nil
} }
association.Error = association.DB.UpdateColumns(updateMap).Error association.Error = association.DB.UpdateColumns(updateMap).Error
} }
case schema.HasOne, schema.HasMany: case schema.HasOne, schema.HasMany:
@ -197,8 +198,7 @@ func (association *Association) Delete(values ...interface{}) error {
switch rel.Type { switch rel.Type {
case schema.BelongsTo: case schema.BelongsTo:
model := reflect.New(rel.Schema.ModelType).Interface() tx := association.DB.Model(reflect.New(rel.Schema.ModelType).Interface())
tx := association.DB.Model(model)
_, pvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, rel.Schema.PrimaryFields) _, pvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, rel.Schema.PrimaryFields)
if pcolumn, pvalues := schema.ToQueryValues(rel.Schema.Table, rel.Schema.PrimaryFieldDBNames, pvs); len(pvalues) > 0 { if pcolumn, pvalues := schema.ToQueryValues(rel.Schema.Table, rel.Schema.PrimaryFieldDBNames, pvs); len(pvalues) > 0 {