Hi
I have a many to many relationship beetween a Custom entity - Training - and the native Contact entity
I add a field in the Training Entity that holds the number of contacts (number of trainees)
I create a Hook to update the number of trainees. AfterRelate is called when I select a contact, but AfterUnrelate is not when I delete a contact from the contacts list.
Am I missing something ?
B/R
JM
I have a many to many relationship beetween a Custom entity - Training - and the native Contact entity
I add a field in the Training Entity that holds the number of contacts (number of trainees)
I create a Hook to update the number of trainees. AfterRelate is called when I select a contact, but AfterUnrelate is not when I delete a contact from the contacts list.
Am I missing something ?
B/R
JM
Code:
class CountTrainees implements AfterRelate, AfterUnrelate
{
public function __construct(
private EntityManager $entityManager,
private Log $log
) {}
public function afterRelate(
Entity $entity,
string $relationName,
Entity $relatedEntity,
array $columnData,
RelateOptions $options
): void {
$this->updateCount($entity, $relationName);
}
public function afterUnrelate(
Entity $entity,
string $relationName,
Entity $relatedEntity,
UnrelateOptions $options
): void {
$this->updateCount($entity, $relationName);
}
