go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.03k stars 3.86k forks source link

fix(scan): update Scan function to reset structs to zero values for each scan #7061

Closed Waldeedle closed 3 weeks ago

Waldeedle commented 3 weeks ago

What did this pull request do?

Accidentally closed #6938 so this is the same PR just with the final implemented solution Addresses #6819 Adding a condition to reset the values of a struct when a scan is initialized to handle nil values from the database

User Case Description

It fixes the example from the docs where you initialize the var once:

    var datasetRow T
    for rows.Next() {
        err := db.ScanRows(rows, &datasetRow)
Waldeedle commented 3 weeks ago

@a631807682 here's the new PR with the final solution. Appreciate all the info and time you've provided on this! 🚀 🎉

Waldeedle commented 3 weeks ago

@a631807682 am I correct in assuming @jinzhu will be merging into master, after reviewing? or would that be you as well?

a631807682 commented 3 weeks ago

I usually wait for at least 2 members to review, and jinzhu will review all PRs and merge them when he is free.