Don't scan last insert id 0

This commit is contained in:
Jinzhu 2020-07-23 23:56:13 +08:00
parent 6ed697dd02
commit c3f52cee8b
1 changed files with 3 additions and 1 deletions

View File

@ -78,7 +78,9 @@ func Create(config *Config) func(db *gorm.DB) {
}
}
case reflect.Struct:
db.Statement.Schema.PrioritizedPrimaryField.Set(db.Statement.ReflectValue, insertID)
if insertID > 0 {
db.Statement.Schema.PrioritizedPrimaryField.Set(db.Statement.ReflectValue, insertID)
}
}
} else {
db.AddError(err)