Return error when creating with unaddressable record in postgres

This commit is contained in:
Jinzhu 2016-11-04 20:57:39 +08:00
parent d5d3e3a67b
commit 9edd66250e
1 changed files with 7 additions and 3 deletions

View File

@ -117,9 +117,13 @@ func createCallback(scope *Scope) {
}
}
} else {
if err := scope.SQLDB().QueryRow(scope.SQL, scope.SQLVars...).Scan(primaryField.Field.Addr().Interface()); scope.Err(err) == nil {
primaryField.IsBlank = false
scope.db.RowsAffected = 1
if primaryField.Field.CanAddr() {
if err := scope.SQLDB().QueryRow(scope.SQL, scope.SQLVars...).Scan(primaryField.Field.Addr().Interface()); scope.Err(err) == nil {
primaryField.IsBlank = false
scope.db.RowsAffected = 1
}
} else {
scope.Err(ErrUnaddressable)
}
}
}