[Hook] AfterUnrelate never call whereas AfterRelate is

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmh
    Junior Member
    • Aug 2024
    • 6

    #1

    [Hook] AfterUnrelate never call whereas AfterRelate is

    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

    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);
        }
  • emillod
    Active Community Member
    • Apr 2017
    • 1607

    #2
    Hello,
    you can check correct hook here: https://github.com/espocrm/espocrm/b...t/Contacts.php

    Comment

    Working...