Announcement

Collapse
No announcement yet.

Method beforeRelate and afterRelate in Hooks

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

  • Method beforeRelate and afterRelate in Hooks

    Hi there! I use validation in my custom Hooks and it works good, but I can't see changes with my relation Many-to-Many. I have alredy read about methods afterRelate and beforeRelate. Method beforeRelate doesn't work in my Hook =( Method afterRelate gave me 500 error (second argument must be string, array given) but I just only write function like beforeSave and don't pass any arrays.
    My code in Hooks:
    PHP Code:
    public function afterRelate(Entity $entitystring $relationNameEntity $foreignEntity, array $options = [])
    {
    $this->throwException('test''test');
    }

    private function 
    throwException($label$log)
    {
    $body Body::create()
    ->
    withMessageTranslation($labelnull)
    ->
    encode();
    throw 
    Error::createWithBody($log$body);
    }
    ​​ 
    What I should to do for beforeRelate or afterRelate methods?

  • #2
    Hi,

    Not an answer, but worth to mention that it's not good to use entity hooks for validation and error response throwing.

    Use record hooks instead: https://docs.espocrm.com/development...kclassnamelist

    Comment


    • #3
      Hello yuri, do you think that you could move this thread to the parent Developer forum ?. I think that this sub-forum should be used strictly for postings that provide examples and guidance, questions should be posted somewhere else in my opinion.
      Last edited by telecastg; 04-15-2023, 05:02 AM.

      Comment

      Working...
      X