When deleting, the hook will be triggered, but the hook entity object attribute has not been assigned
func x(err error) {
err = db.Select("EventActions").Delete(&scene).Error
if err != nil {
return
}
return
}
func (m *EventAction) BeforeDelete(tx *gorm.DB) (err error) {
//Select(""). Delete Association deletion will not inject object attributes into the callback
if m.ID != 0 {
err = m.DelSceneListContent(tx)
if err != nil {
err = errors.Wrap(err, "failed to delete preposition")
return
}
}
return
}
https://gorm.io/zh_CN/docs/associations.html#%E5%B8%A6-Select-%E7%9A%84%E5%88%A0%E9%99%A4 https://gorm.io/zh_CN/docs/hooks.html
I hope I can assign the value correctly
Comment From: StevenOng97
I face the same issue while delete with select
Comment From: a631807682
It depends on whether the mode you pass has a value, we will not execute an additional sql to get the value back, of course you can do this in the hook.