Announcement

Collapse
No announcement yet.

afterRemove hook to reclaculate

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • afterRemove hook to reclaculate

    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

  • #2
    Hi,

    see hook on documentation, you just need this in B entity as hook

    PHP Code:
        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

    Working...
    X