Closed tendollor closed 15 hours ago
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 ✨
@tendollor change your MyAfterUpdate method to the following, just calling Sessoin method to create a new instance, or you can try the WithContext method too:
func MyAfterUpdate(tx *gorm.DB) {
if tx.Statement.Schema.ModelType == reflect.TypeOf(AAA{}) {
var aaas []AAA
// create a new session manually to avoid changes in your old tx instance,
// and this should work with transaction too
if err := tx.Session(&gorm.Session{}).Find(&aaas).Error; err != nil {
log.Println("Failed to fetch aaas:", err)
return
}
log.Println("AAA updated.")
}
}
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 ✨
I encountered an issue while using GORM for update operations. I registered an after update callback function that includes a query operation (tx.Find), but it caused the RowsAffected value of the update operation to always be 0, even though the records were successfully updated. I suspect this is a potential issue in GORM.
test code:
I got this output
version info in go.mod
I want to know how to correctly retrieve the updated record information after an update operation without affecting the RowsAffected value. I need to synchronize the updated data with an in-memory table mapping. How can I achieve this?