Your Question

使用Scan 进行扫描后:行数据内email 为null的情况下,将会被上一个email有值的数据覆盖

The document you expected this should be explained

数据表 数据如图: Gorm Scan进行扫描为null数据结果非预期

// model
type User struct {
    Name     string     `gorm:"column:user_name"`
    Email        *string `gorm:"column:email"`                
}
type userInfo struct {
     Name     string     `gorm:"column:user_name"`
     Email      string     `gorm:"column:email"`                   
}

使用Scan 进行扫描后:行数据内email 为null的情况下,将会被上一个email有值的数据覆盖:

      db.DB.Model(User{}).Where(where).Scan(&[]userInfo)

Gorm Scan进行扫描为null数据结果非预期

解决办法: 把 email 设置为指针变量即可

Expected answer

Comment From: veerdone

一定要设置成指针才行吗,没有其他解决方案吗

Comment From: a631807682

duplicate of https://github.com/go-gorm/gorm/issues/5415