Announcement

Collapse
No announcement yet.

Filter to exclude a related entities instances

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

  • Filter to exclude a related entities instances


    I create two entities "Registration" and "SIM". Then set a relationship between them, One-to-Many. ie. "Registration" (1 <----------> M) "SIM"

    How can I prevent an instance of SIM to be linked to Registration a second time? for example, say if (SIM instance #1) 78880183 is linked to Registration(instance #1) then (Registration instance #2) should not be able to link (SIM instance #1) 78880183 again.

    Kind regards
    Samantha

  • #2
    Hello Samantha.

    You can create a filter for SIM where you check if registrationId is null. http://forum.espocrm.com/forum/devel...-custom-entity http://forum.espocrm.com/forum/devel...-for-drop-down
    And you can create beforeSave hook, where you check if registrationId is changed. If yes, throw an error https://www.espocrm.com/documentatio...lopment/hooks/

    Comment


    • #3
      Hi Tanya,
      Thank you for responding.

      How do a check if the linked field is null?.
      Here are my entities and the hook I created.
      Click image for larger version

Name:	ESPOCRM- FORMREGO-HOOK-BEFORESAVE.png
Views:	428
Size:	38.8 KB
ID:	31621
      Click image for larger version

Name:	ESPOCRM- FORMREGO-fields.png
Views:	396
Size:	75.2 KB
ID:	31622Click image for larger version

Name:	ESPOCRM-SIM-fields.png
Views:	406
Size:	71.3 KB
ID:	31624
      Attached Files

      Comment


      • #4
        As I understand, you want, SIM has only one FORMREGO
        than you need a hook for SIM and checking looks like this
        Code:
        $regoformId = $entity->get('fORMREGOId')
        if ($regoformId) {
           throw \Error('This SIM is used in other FORMREGO');
        }
        (https://github.com/php-fig/fig-stand...ng-standard.md)

        Comment

        Working...
        X