Skip to content

Commit

Permalink
fix: 'Duplicate entry' while Save() composite primary key model
Browse files Browse the repository at this point in the history
  • Loading branch information
YianAndCode committed Nov 23, 2023
1 parent 3207ad6 commit a6f869a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion finisher_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check failure on line 96 in finisher_api.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 unnecessary trailing newline (whitespace) Raw Output: finisher_api.go:96: unnecessary trailing newline (whitespace) }
}
}
}
Expand Down

0 comments on commit a6f869a

Please sign in to comment.