Merge pull request #518 from bojan-embroker/master

Fix Create when dialect does not support last inserted id
This commit is contained in:
Jinzhu 2015-06-08 09:45:09 +08:00
commit cde05781a0
1 changed files with 9 additions and 3 deletions

View File

@ -77,11 +77,17 @@ func Create(scope *Scope) {
} }
} else { } else {
if primaryField == nil { if primaryField == nil {
if results, err := scope.SqlDB().Exec(scope.Sql, scope.SqlVars...); err != nil { if results, err := scope.SqlDB().Exec(scope.Sql, scope.SqlVars...); err == nil {
scope.db.RowsAffected, _ = results.RowsAffected() scope.db.RowsAffected, _ = results.RowsAffected()
} else {
scope.Err(err)
} }
} else if scope.Err(scope.SqlDB().QueryRow(scope.Sql, scope.SqlVars...).Scan(primaryField.Field.Addr().Interface())) == nil { } else {
if err := scope.Err(scope.SqlDB().QueryRow(scope.Sql, scope.SqlVars...).Scan(primaryField.Field.Addr().Interface())); err == nil {
scope.db.RowsAffected = 1 scope.db.RowsAffected = 1
} else {
scope.Err(err)
}
} }
} }
} }