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{
|
onConflict.DoUpdates = clause.AssignmentColumns(columns)
|
||||||
Columns: make([]clause.Column, len(stmt.Schema.PrimaryFieldDBNames)),
|
|
||||||
DoUpdates: clause.AssignmentColumns(columns),
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx, field := range stmt.Schema.PrimaryFields {
|
// use primary fields as default OnConflict columns
|
||||||
onConflict.Columns[idx] = clause.Column{Name: field.DBName}
|
if len(onConflict.Columns) == 0 {
|
||||||
|
for _, field := range stmt.Schema.PrimaryFields {
|
||||||
|
onConflict.Columns = append(onConflict.Columns, clause.Column{Name: field.DBName})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.AddClause(onConflict)
|
stmt.AddClause(onConflict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue