Method beforeRelate and afterRelate in Hooks
Collapse
X
-
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. -
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...kclassnamelistLeave a comment:
-
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:
What I should to do for beforeRelate or afterRelate methods?PHP Code:public function afterRelate(Entity $entity, string $relationName, Entity $foreignEntity, array $options = []) { $this->throwException('test', 'test'); } private function throwException($label, $log) { $body = Body::create() ->withMessageTranslation($label, null) ->encode(); throw Error::createWithBody($log, $body); }Tags: None

Leave a comment: