APIv4 Explorer - Fix display of bridge entity fields for symmetric bridge
authorColeman Watts <coleman@civicrm.org>
Fri, 16 Jul 2021 15:06:41 +0000 (11:06 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 18 Jul 2021 21:21:53 +0000 (17:21 -0400)
Symmetric bridge entities such as RelationshipCache which joins Contact to Contact
need to have the second entity id availble to join on.

ang/api4Explorer/Explorer.js

index a0cdc38ac82eb81965b6c20e6b3261232436bebb..2bdaa72b11c4f34fea2577e1a0c7a69cee390211 100644 (file)
           if (join.bridge) {
             var bridgeFields = _.cloneDeep(entityFields(join.bridge)),
               bridgeEntity = getEntity(join.bridge),
-              joinFieldNames = _.pluck(joinFields, 'name');
+              joinFieldNames = _.pluck(joinFields, 'name'),
+              // Check if this is a symmetric bridge e.g. RelationshipCache joins Contact to Contact
+              bridgePair = _.keys(bridgeEntity.bridge),
+              symmetric = getField(bridgePair[0], join.bridge).entity === getField(bridgePair[1], join.bridge).entity;
             _.each(bridgeFields, function(field) {
               if (
                 // Only include bridge fields that link back to the original entity
-                (!bridgeEntity.bridge[field.name] || field.fk_entity !== join.entity) &&
+                (!bridgeEntity.bridge[field.name] || field.fk_entity !== join.entity || symmetric) &&
                 // Exclude fields with the same name as those in the original entity
                 !_.includes(joinFieldNames, field.name)
               ) {