GORM Playground Link

https://github.com/go-gorm/playground/pull/1

Description

数据表 数据如图: 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 设置为指针变量即可

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking