You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a system where several microservices uses Gorm. I would like to update Gorm to set the field UpdatedAt to the same timestamp DeletedAt get set to during a soft-delete.
Because there are many microservices with many models, I would like to do this without having to modify the model struct themselves. Ideally via a hook or something similar.
I have tried using a global hook to modify the clause.Set of the statement to include UpdatedAt, but it seems that soft-delete.go will overwrite it.
How can I go about doing this?
The document you expected this should be explained
It would be great if I could define a global hook and modify the Set statement before the update/delete query is called.
db.Callback().Delete().Before("gorm:delete").Register(hookName, updateUpdatedAtWithSoftDelete)
funcupdateUpdatedAtWithSoftDelete(db*gorm.DB) {
//Overwrite the Set query here
}
Query I want
UPDATE`database_name`.`table_name`SET`deleted_at`=?, `updated_at`=? WHERE`database_name`.`id`= ? AND`database_name`.`deleted_at` IS NULL`
Thank you for your assistance.
The text was updated successfully, but these errors were encountered:
Your Question
Hello.
I have a system where several microservices uses Gorm. I would like to update Gorm to set the field
UpdatedAt
to the same timestampDeletedAt
get set to during a soft-delete.Because there are many microservices with many models, I would like to do this without having to modify the model struct themselves. Ideally via a hook or something similar.
I have tried using a global hook to modify the
clause.Set
of the statement to include UpdatedAt, but it seems thatsoft-delete.go
will overwrite it.How can I go about doing this?
The document you expected this should be explained
https://gorm.io/docs/hooks.html
Expected answer
It would be great if I could define a global hook and modify the Set statement before the update/delete query is called.
Query I want
Thank you for your assistance.
The text was updated successfully, but these errors were encountered: