fix(scan): update Scan function to reset structs to zero values for each scan#7061
fix(scan): update Scan function to reset structs to zero values for each scan#7061jinzhu merged 1 commit intogo-gorm:masterfrom
Conversation
|
@a631807682 here's the new PR with the final solution. Appreciate all the info and time you've provided on this! 🚀 🎉 |
|
@a631807682 am I correct in assuming @jinzhu will be merging into master, after reviewing? or would that be you as well? |
|
I usually wait for at least 2 members to review, and jinzhu will review all PRs and merge them when he is free. |
|
OMG, I've been treating this as a feature the whole time. |
|
It doesn't seem like a "Non breaking API changes". Is this the expected behavior of this function itself? |
|
I'm not sure if this is related, but there's a significant change in the We used to use type SomeStruct struct {
Name string
Date null.Time
Description string
ID uint64
}
data := SomeStruct{
ID: 1,
Date: null.TimeFrom(time.Now()),
}
db.Table("some_table").
Select("name, description").
Where("id = ?", data.ID).
Scan(&data)The intention was to fill in new data while keeping the already populated fields intact. |
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: