Your Question
The following code works well in gorm v1.
type Object struct {
...
}
func (obj *Object) Scan(value interface{}) error {
if value != nil {
if e := json.Unmarshal(value.([]byte), r); e != nil {
return e
}
}
return nil
}
var face interface{}
var model Object{}
face = model
db.Model(face).Updates(...)
But in gorm v2, db.Model(face).Updates(...) will call the Scan() function, and panics with the following.
test panicked: interface conversion: interface {} is Object, not []uint8
I don't know why gormv2 calls Scan() when using interface as the model. And if I want to use interface as the model to support different structs, how can I do that? Thank you so much!
The document you expected this should be explained
Expected answer
Comment From: JiawenFan810
I think that Value() should be called before Scan(), but I didn't see it in the log stack.
Comment From: li-jin-gou
refer to - https://gorm.cn/docs/data_types.html - https://gorm.io/docs/serializer.html