From 938618a3e2fc17e93fc3cc5b1608d3bce0e3036f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 12 Jun 2014 11:54:47 +0800 Subject: [PATCH] Refact callback_create --- callback_create.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/callback_create.go b/callback_create.go index 1cf4fcb4..52858a41 100644 --- a/callback_create.go +++ b/callback_create.go @@ -26,15 +26,8 @@ func Create(scope *Scope) { // set create sql var sqls, columns []string - primaryKeyPredefined := false for _, field := range scope.Fields() { - if field.DBName == scope.PrimaryKey() { - primaryKeyValue := fmt.Sprintf("%v", field.Value) - if primaryKeyValue != "" && primaryKeyValue != "0" { - primaryKeyPredefined = true - } - } - if len(field.SqlTag) > 0 && !field.IsIgnored && (field.DBName != scope.PrimaryKey() || primaryKeyPredefined) { + if len(field.SqlTag) > 0 && !field.IsIgnored && (field.DBName != scope.PrimaryKey() || !scope.PrimaryKeyZero()) { columns = append(columns, scope.Quote(field.DBName)) sqls = append(sqls, scope.AddToVars(field.Value)) } @@ -72,7 +65,7 @@ func Create(scope *Scope) { } } - if !scope.HasError() && !primaryKeyPredefined { + if !scope.HasError() { scope.SetColumn(scope.PrimaryKey(), id) } }