Allow customize AutoIncrement for primary field

This commit is contained in:
Jinzhu 2020-07-08 18:50:49 +08:00
parent 30188e7aa4
commit e1084e78d0
1 changed files with 5 additions and 2 deletions

View File

@ -187,10 +187,13 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
if !field.HasDefaultValue || field.DefaultValueInterface != nil { if !field.HasDefaultValue || field.DefaultValueInterface != nil {
schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field) schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field)
} }
if _, ok := field.TagSettings["AUTOINCREMENT"]; !ok {
field.HasDefaultValue = true field.HasDefaultValue = true
field.AutoIncrement = true field.AutoIncrement = true
} }
} }
}
callbacks := []string{"BeforeCreate", "AfterCreate", "BeforeUpdate", "AfterUpdate", "BeforeSave", "AfterSave", "BeforeDelete", "AfterDelete", "AfterFind"} callbacks := []string{"BeforeCreate", "AfterCreate", "BeforeUpdate", "AfterUpdate", "BeforeSave", "AfterSave", "BeforeDelete", "AfterDelete", "AfterFind"}
for _, name := range callbacks { for _, name := range callbacks {