Foreign field from parent relation ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tothewine
    Active Community Member
    • Jan 2018
    • 373

    Foreign field from parent relation ?

    The Entity Manager does not show the Parent link when I create a foreign field. How do I foreign-reference a field from the parent entity?
    If I somehow have success in selecting a field and the entity type of the parent does not contain the foreign field will it be a fatal error (api request failing) or a soft one (where espo recovers and shows null in the returned entity) ?
  • yuri
    Member
    • Mar 2014
    • 8485

    #2
    Parent link is not supported in foreign fields.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • tothewine
      Active Community Member
      • Jan 2018
      • 373

      #3
      Ok, I verified it causes error 502 if forced. What do you recommend for showing foreign fields from the parent ?

      Comment

      • yuri
        Member
        • Mar 2014
        • 8485

        #4
        Write code in loadAdditionalFields method https://github.com/espocrm/espocrm/b...ecord.php#L443 that will load parent entity and set notStorable a field with a value from that entity.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • tothewine
          Active Community Member
          • Jan 2018
          • 373

          #5
          Is there a way (also by editing custom entityDef) to create a "one sided relation" link to be used for this? Like the createdBy/modifiedBy links. I would then use that to configure the foreign keys normally with entity manager.

          Comment

          • yuri
            Member
            • Mar 2014
            • 8485

            #6
            Yes.

            1. Create one-to-many link.
            2. Fill link id attribute with Formula.
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            • tothewine
              Active Community Member
              • Jan 2018
              • 373

              #7
              After creating a one to many link I now have this in the entity json:

              Field section:
              Code:
               "xxxleads1": {     "type": "linkMultiple",     "layoutDetailDisabled": true,     "layoutMassUpdateDisabled": true,     "noLoad": true,     "importDisabled": true,     "isCustom": true }
              Link section:

              Code:
               "xxxleads1": {     "type": "hasMany",     "foreign": "xxxcall",     "entity": "Lead",     "audited": false,     "isCustom": true }
              What do I do now?
              Last edited by tothewine; 01-24-2019, 06:55 PM.

              Comment

              • yuri
                Member
                • Mar 2014
                • 8485

                #8
                I think you created wrong direction link.

                Administration > Entity Manager > edit formula for your entity

                ifThenElse(parentType == 'Lead', leadId = parentId);

                If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                Comment

                • tothewine
                  Active Community Member
                  • Jan 2018
                  • 373

                  #9
                  Ok I reversed the direction. The entityDef is in the screenshot. Now I put this in the entity formula:
                  Code:
                  ifThenElse(parentType == 'Lead', kLeadId = parentId);
                  For existing entities I have to do a mass update of some value to trigger the formula?


                  What is the difference between this and the 'belongsTo' link type ?
                  Last edited by tothewine; 01-24-2019, 07:42 PM.

                  Comment

                  • tothewine
                    Active Community Member
                    • Jan 2018
                    • 373

                    #10
                    But how can emailAddress or multi-enums be referenced as foreign keys?

                    Comment

                    Working...