can i have a sample of code for afterRemove hook to reclaculate fields?
A has many Bs, if one B is deleted and I need to recalculae A fields
A has many Bs, if one B is deleted and I need to recalculae A fields
public function afterRemove(Entity $entity, array $options): void
{
if ($entity->get('aId'))
{
$a = $this->em->getEntityById('A', $entity->get('aId') );
if ($a){
$this->em->saveEntity($a, [
'modifiedById' => $this->user->getId(),
]);
}
}
}
Comment