Refactor callbacks

This commit is contained in:
Jinzhu 2020-06-09 10:17:24 +08:00
parent 649d02fddd
commit c4872cddfd
1 changed files with 2 additions and 5 deletions

View File

@ -193,22 +193,19 @@ func ConvertToCreateValues(stmt *gorm.Statement) clause.Values {
return ConvertSliceOfMapToValuesForCreate(stmt, value) return ConvertSliceOfMapToValuesForCreate(stmt, value)
default: default:
var ( var (
values = clause.Values{Columns: make([]clause.Column, len(stmt.Schema.DBNames))} values = clause.Values{Columns: make([]clause.Column, 0, len(stmt.Schema.DBNames))}
selectColumns, restricted = SelectAndOmitColumns(stmt, true, false) selectColumns, restricted = SelectAndOmitColumns(stmt, true, false)
curTime = stmt.DB.NowFunc() curTime = stmt.DB.NowFunc()
isZero = false isZero = false
) )
var columns int
for _, db := range stmt.Schema.DBNames { for _, db := range stmt.Schema.DBNames {
if field := stmt.Schema.FieldsByDBName[db]; !field.HasDefaultValue || field.DefaultValueInterface != nil { if field := stmt.Schema.FieldsByDBName[db]; !field.HasDefaultValue || field.DefaultValueInterface != nil {
if v, ok := selectColumns[db]; (ok && v) || (!ok && !restricted) { if v, ok := selectColumns[db]; (ok && v) || (!ok && !restricted) {
values.Columns[columns] = clause.Column{Name: db} values.Columns = append(values.Columns, clause.Column{Name: db})
columns++
} }
} }
} }
values.Columns = values.Columns[:columns]
switch stmt.ReflectValue.Kind() { switch stmt.ReflectValue.Kind() {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array: