Your Question
It seems AfterDelete hook does not triggered when using Batch Delete.
Example: tx.Model(&User{}).Where(condition).Delete(&[]User{}).Error
but it does triggered if i delete them one by one using for loop with tx.Delete(&user)
The document you expected this should be explained
Expected answer
Hook AfterDelete could be triggered with both way, deleting in Batch or One by one.
Comment From: Quaqmre
It is true , i check it my local computer and i encounter same behaviour,
Comment From: a631807682
It is work for me, can you reproduced on go-gorm/playground?
Comment From: mdanialr
@a631807682 i also read this in the docs. '...those methods will be called when deleting a record...'. whats the word deleting a record means?
Comment From: jinzhu
tx.Model(&User{}).Where(condition).Delete(&[]User{}).Error
In your case, the after delete method will called for each record of &[]User{}, as the slice is empty, so no one will be called.
We don't query out all matched data before deleting, so we can't call the method for all data deleted, but using the data you passed in.