Description
type BaseModel struct {
CreatedAt time.Time
UpdatedAt time.Time
}
type Package struct {
Id int64 `gorm:"primarykey"`
Name string `gorm:"type:varchar(255) comment '套餐名称';not null"`
Money float32 `gorm:"type:decimal(10,2) comment '套餐金额';not null"`
Fields string `gorm:"type:longtext comment '套餐项';not null"`
Status uint8 `gorm:"default:1;type:tinyint(1) comment '状态: 0 下架 1 上架 2 作废';not null"`
BaseModel
}
// 操作更新
func (m *defaultPackageModel) Update(ctx context.Context, data *Package) error {
old, err := m.FindOne(ctx, data.Id)
if err != nil && !errors.Is(err, ErrNotFound) {
return err
}
err = m.ExecCtx(ctx, func(conn *gorm.DB) error {
return conn.Save(data).Error
}, m.getCacheKeys(old)...)
return err
}
// 更新数据库
err = l.svcCtx.PackageModel.Update(l.ctx, &model.Package{
Id: in.Id,
Name: in.Name,
Money: in.Money,
Fields: in.Fields,
Status: uint8(in.Status),
})
补充描述
经过测试 如果给CreatedAt 增加 gorm:"<-:create" 则是正常的
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: saeidee
Can you please submit a Plaground PR with the issue?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: sunboatz
Check the created_at field, maybe ON UPDATE CURRENT_TIMESTAMP is assigned.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: Tension-Z
Check the
created_atfield, maybeON UPDATE CURRENT_TIMESTAMPis assigned.
Didn't do this
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨