From 9edd66250e8ae11d572213054643b7bb1ce4d102 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 4 Nov 2016 20:57:39 +0800 Subject: [PATCH] Return error when creating with unaddressable record in postgres --- callback_create.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/callback_create.go b/callback_create.go index 7a6dea94..f0709880 100644 --- a/callback_create.go +++ b/callback_create.go @@ -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) } } }