Describe the feature
Hi everyone,
Since using the v2 of gorm, I miss a bit the helper RecordNotFound() that we used to have in the v1 for a gorm.DB object.
Would it be possible / welcome to have that helper again ?
Maybe there is a "reason" that it has been removed since the v2 is a complete review of the v1.
Motivation
The main reason is that, it is a bit overwhelmed to always write the following code to check if the result (s) has / have been found:
if err := db.Model(&user).Association("Settings").Find(&settings).Error; err != nil && errors.Is(err, gorm.ErrorRecordNotFound) {
// Handle the error here
}
rather than a simple
if db.Model(&user).Association("Settings").Find(&settings).RecordNotFound() {
// Handle the error here
}
@jinzhu what do you think ?
Comment From: jinzhu
Hello @maeglindeveloper
I would not like to have the API in V2, it was misused in V1 a lot and causing confusions, maybe better to write a helper in your application.
Thank you for your suggestion.
Comment From: maeglindeveloper
@jinzhu I don't really understand the reason why it can be misused ? My main concern is that, moving from v1 to v2, I should move lots of packages, lots of code to that new and a bit long way to check quickly if a result match RecordNotFound().... Can't we reconsider that feature request ?
Comment From: duaneking
I would not like to have the API in V2, it was misused in V1 a lot and causing confusions, maybe better to write a helper in your application.
What do you mean?
From my perspective, the opposite is true.
Comment From: jinzhu
Many users thought RecordNotFound would trigger a SQL query instead of just checking the current error.