Skip to content

[Question] AfterDelete Hook documentation is unclear #816

@keif888

Description

@keif888

Document Link

Deleting an object

Your Question

The documentation doesn't state what the AfterDelete hook receives in the struct that is provided to the hook.
eg. If you issue a Delete(struct, id) then AfterDelete gets the struct, but NOT the id.

Expected answer

Clear documentation on what GORM provides in the struct passed to the hook.

  • Use Case 1 - Struct populated with ID
    • AfterDelete is called ONCE and receives the struct with ID (and other fields if provided), UpdatedAt, and DeletedAt populated
  • Use Case 2 - Struct without ID, and list of ID(s) provided in delete conditions
    • AfterDelete is called ONCE and receives the struct without ID (but other fields if provided), UpdatedAt, and DeletedAt populated
  • Use Case 3 - Empty Struct, Delete using Where clause
    • AfterDelete is called ONCE and receives a struct with UpdatedAt, and DeletedAt populated

See go-gorm/playground#792 for example tests that show some of the ways that you can execute a delete.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions