mirror of https://github.com/go-gorm/gorm.git
Refact callback_create
This commit is contained in:
parent
d2e526bc2d
commit
938618a3e2
|
@ -26,15 +26,8 @@ func Create(scope *Scope) {
|
||||||
// set create sql
|
// set create sql
|
||||||
var sqls, columns []string
|
var sqls, columns []string
|
||||||
|
|
||||||
primaryKeyPredefined := false
|
|
||||||
for _, field := range scope.Fields() {
|
for _, field := range scope.Fields() {
|
||||||
if field.DBName == scope.PrimaryKey() {
|
if len(field.SqlTag) > 0 && !field.IsIgnored && (field.DBName != scope.PrimaryKey() || !scope.PrimaryKeyZero()) {
|
||||||
primaryKeyValue := fmt.Sprintf("%v", field.Value)
|
|
||||||
if primaryKeyValue != "" && primaryKeyValue != "0" {
|
|
||||||
primaryKeyPredefined = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(field.SqlTag) > 0 && !field.IsIgnored && (field.DBName != scope.PrimaryKey() || primaryKeyPredefined) {
|
|
||||||
columns = append(columns, scope.Quote(field.DBName))
|
columns = append(columns, scope.Quote(field.DBName))
|
||||||
sqls = append(sqls, scope.AddToVars(field.Value))
|
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)
|
scope.SetColumn(scope.PrimaryKey(), id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue