Announcement

Collapse
No announcement yet.

Foreign field from parent relation ?

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

  • 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) ?

  • #2
    Parent link is not supported in foreign fields.

    Comment


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

      Comment


      • #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.

        Comment


        • #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


          • #6
            Yes.

            1. Create one-to-many link.
            2. Fill link id attribute with Formula.

            Comment


            • #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


              • #8
                I think you created wrong direction link.

                Administration > Entity Manager > edit formula for your entity

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

                Comment


                • #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


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

                    Comment

                    Working...
                    X