Fix query in afterDelete