开发者

GORM hooks - Cannot get the ID when update multiple rows

开发者 https://www.devze.com 2022-12-07 19:16 出处:网络
I have the update code like this: db.Model(&models.DailyPlan{}). Where("daily_plan_id IN ?", dailyPlanIds).

I have the update code like this:

db.Model(&models.DailyPlan{}).
   Where("daily_plan_id IN ?", dailyPlanIds).
   Updates(updateClause).Error

and hooks:

func (d *DailyPlan) AfterSave(tx *gorm.DB) (err error) {
   // blah bla开发者_运维百科h
   return
}

But when I run the update code above, in my hooks, I cannot get the ID (daily_plan_id) (only the fields in the updateClause have data).

How can I get the ID that I send in dailyPlanIds?


You can use Set/Get based on here

0

精彩评论

暂无评论...
验证码 换一张
取 消