// updateTimeStampForUpdateCallback will set `UpdatedAt` when updating funcupdateTimeStampForUpdateCallback(scope *Scope) { if _, ok := scope.Get("gorm:update_column"); !ok { scope.SetColumn("UpdatedAt", scope.db.nowFunc()) } }
// updateTimeStampForCreateCallback will set `CreatedAt`, `UpdatedAt` when creating funcupdateTimeStampForCreateCallback(scope *Scope) { if !scope.HasError() { now := scope.db.nowFunc()
if createdAtField, ok := scope.FieldByName("CreatedAt"); ok { if createdAtField.IsBlank { createdAtField.Set(now) } }
if updatedAtField, ok := scope.FieldByName("UpdatedAt"); ok { if updatedAtField.IsBlank { updatedAtField.Set(now) } } } }
// updateTimeStampForUpdateCallback will set `UpdatedAt` when updating funcupdateTimeStampForUpdateCallback(scope *gorm.Scope) { if _, ok := scope.Get("gorm:update_column"); !ok { _ = scope.SetColumn("UpdatedAt", time.Now().Unix()) } }