From 94f56e646bb69d8128545a1b0cee90eb783bafca Mon Sep 17 00:00:00 2001 From: Bojan Petrovic Date: Thu, 4 Jun 2015 13:47:25 +0200 Subject: [PATCH 1/2] Fix Create when dialect does not support last inserted id --- callback_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callback_create.go b/callback_create.go index e7ec40bb..9f0c9bc2 100644 --- a/callback_create.go +++ b/callback_create.go @@ -77,7 +77,7 @@ func Create(scope *Scope) { } } else { 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() } } else if scope.Err(scope.SqlDB().QueryRow(scope.Sql, scope.SqlVars...).Scan(primaryField.Field.Addr().Interface())) == nil { From d9faa4949cf3cc73602389ba5bbf95ea012ca9eb Mon Sep 17 00:00:00 2001 From: Bojan Petrovic Date: Thu, 4 Jun 2015 14:23:57 +0200 Subject: [PATCH 2/2] Fix Create error reporting. --- callback_create.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/callback_create.go b/callback_create.go index 9f0c9bc2..7f21ed6a 100644 --- a/callback_create.go +++ b/callback_create.go @@ -79,9 +79,15 @@ func Create(scope *Scope) { if primaryField == nil { if results, err := scope.SqlDB().Exec(scope.Sql, scope.SqlVars...); err == nil { scope.db.RowsAffected, _ = results.RowsAffected() + } else { + scope.Err(err) + } + } else { + if err := scope.Err(scope.SqlDB().QueryRow(scope.Sql, scope.SqlVars...).Scan(primaryField.Field.Addr().Interface())); err == nil { + scope.db.RowsAffected = 1 + } else { + scope.Err(err) } - } else if scope.Err(scope.SqlDB().QueryRow(scope.Sql, scope.SqlVars...).Scan(primaryField.Field.Addr().Interface())) == nil { - scope.db.RowsAffected = 1 } } }