Announcement

Collapse
No announcement yet.

unrelate function on Hook has no effect

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

  • unrelate function on Hook has no effect

    Hi,

    Following directions from https://docs.espocrm.com/development/orm/, I do unrelate as follows in a Hook :

    PHP Code:
    $entityManager
    ->getRDBRepository('Account')
    ->
    getRelation($account'opportunities')
    ->
    unrelate($opportunity); 
    I verified by logging that the entities exist and that they are correclty related as I can see the corrects records ids when printing as follows

    PHP Code:
    $opportunityCollection $entityManager
    ->getRDBRepository('Account')
    ->
    getRelation($account'opportunities')
    ->
    limit(010)
    ->
    find(); 
    Even afterRelate Hooks are triggerred so I assume taht the unrelate is actually executed but for a reason, the entities remain related afterwards.

    If I unrelate from frontend GUI in bottom panel, it works fine. But when I unrelate in backend as above, it does not work. Every other statement executed at the same time in my Hook are done properly. I don't have any error logged in backend logs nor in console.

    Any help on what direction to search would be highly appreciated as I'm kind of stuck with this issue.

    Thanks !
    Last edited by huscmk; 12-02-2023, 09:42 AM.

  • #2
    if you have the latest version you might try this code below:

    PHP Code:
    $entityManager->getRDBRepository('Account')
                    ->
    getRelation($account'opportunities')
                    ->
    unrelateById($opportunityId);​​ 
    Rabii
    Web Dev

    Comment


    • huscmk
      huscmk commented
      Editing a comment
      Thank you for your help. I will give it a try.
Working...
X