diff --git a/callbacks/helper.go b/callbacks/helper.go index 3ac63fa1..ad85a1c6 100644 --- a/callbacks/helper.go +++ b/callbacks/helper.go @@ -41,16 +41,21 @@ func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]inter // ConvertSliceOfMapToValuesForCreate convert slice of map to values func ConvertSliceOfMapToValuesForCreate(stmt *gorm.Statement, mapValues []map[string]interface{}) (values clause.Values) { var ( - columns = make([]string, 0, len(mapValues)) - result = map[string][]interface{}{} - selectColumns, restricted = stmt.SelectAndOmitColumns(true, false) + columns = make([]string, 0, len(mapValues)) ) + // when the length of mapValues,return directly here + // no need to call stmt.SelectAndOmitColumns method if len(mapValues) == 0 { stmt.AddError(gorm.ErrEmptySlice) return } + var ( + result = make(map[string][]interface{}, len(mapValues)) + selectColumns, restricted = stmt.SelectAndOmitColumns(true, false) + ) + for idx, mapValue := range mapValues { for k, v := range mapValue { if stmt.Schema != nil {