I have 3nentities 'A','B','C' A is linked to both of them with one-many (2 links ab, ac), how to set up please a afterRemove hook to delete All the retaled Bs linked to an A after removing a A?
thank you so much
is this code correct?
thank you so much
is this code correct?
PHP Code:
<?php
namespace Espo\Custom\Hooks\A;
use Espo\ORM\Entity;
class AfterRemove extends \Espo\Core\Hooks\Base
{
public static $order = 10;
public function afterRemove(Entity $entity)
{
$entityManager = $this->getEntityManager();
// Get related 'B' entities
$relatedBs = $entityManager->getRepository('B')->where([
'aId' => $entity->id
])->find();
// Delete each related 'B' entity
foreach ($relatedBs as $bEntity) {
$entityManager->removeEntity($bEntity);
}
}
}
Comment