fix: 'Duplicate entry' while Save() composite primary key model
This commit is contained in:
parent
3207ad6033
commit
a6f869a340
@ -89,7 +89,11 @@ func (db *DB) Save(value interface{}) (tx *DB) {
|
||||
if err := tx.Statement.Parse(value); err == nil && tx.Statement.Schema != nil {
|
||||
for _, pf := range tx.Statement.Schema.PrimaryFields {
|
||||
if _, isZero := pf.ValueOf(tx.Statement.Context, reflectValue); isZero {
|
||||
return tx.callbacks.Create().Execute(tx)
|
||||
if _, ok := tx.Statement.Clauses["ON CONFLICT"]; !ok {
|
||||
tx = tx.Clauses(clause.OnConflict{UpdateAll: true})
|
||||
}
|
||||
return tx.callbacks.Create().Execute(tx.Set("gorm:update_track_time", true))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user