我有一个模型:
type User struct {
ID uint
Name string
Age int
Gender string
// hundreds of fields
}
使用此挂钩:
func (m *User) AfterFind(tx *gorm.DB) (err error) {
// I don't know how to get Gender value of APIUser struct from here
return
}
和这个聪明的 Select struct :
type APIUser struct {
ID uint
Gender string
}
然后,我运行以下查询:
DB.Model(&User{}).Find(&APIUser{}, id)
在AfterFind()钩子中,我想在将从数据库检索到的数据发送到客户端之前对其进行操作,但我无法在该钩子中获得值.如何做到这一点呢?