mirror of https://github.com/go-gorm/gorm.git
Refactor OnConflict.UpdateALl
This commit is contained in:
parent
07f3795f93
commit
27bb9137d3
|
@ -353,15 +353,14 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) {
|
|||
}
|
||||
}
|
||||
|
||||
onConflict := clause.OnConflict{
|
||||
Columns: make([]clause.Column, len(stmt.Schema.PrimaryFieldDBNames)),
|
||||
DoUpdates: clause.AssignmentColumns(columns),
|
||||
}
|
||||
onConflict.DoUpdates = clause.AssignmentColumns(columns)
|
||||
|
||||
for idx, field := range stmt.Schema.PrimaryFields {
|
||||
onConflict.Columns[idx] = clause.Column{Name: field.DBName}
|
||||
// use primary fields as default OnConflict columns
|
||||
if len(onConflict.Columns) == 0 {
|
||||
for _, field := range stmt.Schema.PrimaryFields {
|
||||
onConflict.Columns = append(onConflict.Columns, clause.Column{Name: field.DBName})
|
||||
}
|
||||
}
|
||||
|
||||
stmt.AddClause(onConflict)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue