forked from mirror/gorm
Fix insert empty record into database
This commit is contained in:
parent
1120451108
commit
ddc1f9156a
|
@ -32,13 +32,20 @@ func Create(scope *Scope) {
|
|||
}
|
||||
}
|
||||
|
||||
scope.Raw(fmt.Sprintf(
|
||||
"INSERT INTO %v (%v) VALUES (%v) %v",
|
||||
scope.TableName(),
|
||||
strings.Join(columns, ","),
|
||||
strings.Join(sqls, ","),
|
||||
scope.Dialect().ReturningStr(scope.PrimaryKey()),
|
||||
))
|
||||
if len(columns) == 0 {
|
||||
scope.Raw(fmt.Sprintf("INSERT INTO %v DEFAULT VALUES %v",
|
||||
scope.TableName(),
|
||||
scope.Dialect().ReturningStr(scope.PrimaryKey()),
|
||||
))
|
||||
} else {
|
||||
scope.Raw(fmt.Sprintf(
|
||||
"INSERT INTO %v (%v) VALUES (%v) %v",
|
||||
scope.TableName(),
|
||||
strings.Join(columns, ","),
|
||||
strings.Join(sqls, ","),
|
||||
scope.Dialect().ReturningStr(scope.PrimaryKey()),
|
||||
))
|
||||
}
|
||||
|
||||
// execute create sql
|
||||
var id interface{}
|
||||
|
|
Loading…
Reference in New Issue