Fix insert empty record into database

This commit is contained in:
Jinzhu 2014-04-29 17:42:10 +08:00
parent 1120451108
commit ddc1f9156a
1 changed files with 14 additions and 7 deletions

View File

@ -32,6 +32,12 @@ func Create(scope *Scope) {
} }
} }
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( scope.Raw(fmt.Sprintf(
"INSERT INTO %v (%v) VALUES (%v) %v", "INSERT INTO %v (%v) VALUES (%v) %v",
scope.TableName(), scope.TableName(),
@ -39,6 +45,7 @@ func Create(scope *Scope) {
strings.Join(sqls, ","), strings.Join(sqls, ","),
scope.Dialect().ReturningStr(scope.PrimaryKey()), scope.Dialect().ReturningStr(scope.PrimaryKey()),
)) ))
}
// execute create sql // execute create sql
var id interface{} var id interface{}