tx = tx.callbacks.Create().Execute(tx.Set("gorm:update_track_time", true)) case reflect.Struct: if err := tx.Statement.Parse(value); err == nil && tx.Statement.Schema != nil { for _, pf := range tx.Statement.Schema.PrimaryFields { if _, isZero := pf.ValueOf(tx.Statement.Co...
tx = tx.callbacks.Create().Execute(tx.Set("gorm:update_track_time", true)) case reflect.Struct: if err := tx.Statement.Parse(value); err == nil && tx.Statement.Schema != nil { for _, pf := range tx.Statement.Schema.PrimaryFields { if _, isZero := pf.ValueOf(tx.Statement.Co...
}elseiffield.AutoCreateTime >0|| field.AutoUpdateTime >0{ stmt.AddError(field.Set(stmt.Context, stmt.ReflectValue, curTime)) values.Values[0][idx], _ = field.ValueOf(stmt.Context, stmt.ReflectValue) } }elseiffield.AutoUpdateTime >0&& updateTrackTime { stmt.AddError(field.Set(stmt.Con...
tx = tx.callbacks.Create().Execute(tx.Set("gorm:update_track_time",true))casereflect.Struct:iferr := tx.Statement.Parse(value); err ==nil&& tx.Statement.Schema !=nil{for_, pf :=rangetx.Statement.Schema.PrimaryFields {if_, isZero := pf.ValueOf(tx.Statement.Context, reflectValue); ...
UpdatedAt time.Time DeletedAt DeletedAt `gorm:"index"` }复制代码 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Model定义了ID、CreatedAt、UpdatedAt、DeletedAt属性 ParseField gorm.io/gorm@v1.20.10/schema/field.go func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { ...
field.AutoUpdateTime = UnixSecond } }//...return field } ParseField方法会解析field的属性,如果field的name为CreatedAt或者UpdatedAt,且dataType为Time、Int、Unit或者tag标注了AUTOCREATETIME或者AUTOUPDATETIME,则会设置field.AutoCreateTime或者field.AutoUpdateTime TimeType...
Set("gorm:update_track_time", true)) case reflect.Struct: if err := tx.Statement.Parse(value); err == nil && tx.Statement.Schema != nil { for _, pf := range tx.Statement.Schema.PrimaryFields { if _, isZero := pf.ValueOf(tx.Statement.Context, reflectValue); isZero { ...
CreatedAt time.Time UpdatedAt time.Time} 约定 GORM 倾向于约定,而不是配置。默认情况下,GORM使用ID作为主键,使用结构体名的蛇形复数作为表名,字段名的蛇形作为列名,并使用CreatedAt、UpdatedAt字段追踪创建、更新时间 遵循GORM 已有的约定,可以减少您的配置和代码量。如果约定不符合您的需求,GORM 允许您自定义配置...
uses CreatedAt, UpdatedAt to track creating/updating time 日期时间 datetime/date/timesatmp -> time.Time, 运算使用 carbon 库 time -> 使用 string 不推荐null, 可以为null使用指针或者对应对应null类型 mark tag:gorm:"-".ignore 内嵌字段gorm.Model ...
autoCreateTimecreatedtrack current time when creating, for int fields, it will track unix seconds, use value nano/milli to track unix nano/milli seconds, e.g: autoCreateTime:nanoThis field will be filled in current time on insert autoUpdateTimeupdatedtrack current time when creating/updating, ...