1

I am using this example https://developers.arcgis.com/javascript/3/jssamples/fl_query_related.html

to develop an application which queries related features. I have two feature classes and have created a N-M relationship class. The objective is to click on an electric feeder and query the related customers. There are 26 electrical feeders and over 400 customers. My relationship class was based on the OBJECTIDs being the primary keys and the foreign keys being the "feederID" that the structures have and the that the customers are assigned to.

Ideally, I'd expect to see several customers per feeder, but based on my logic in this code sample, I am only returning the matching ObjectIDs per feeder.

What should be changed to return each customer which shares the same feeder?

 function findRelatedRecords(evt) {
        var features = evt.features;
        var relatedTopsQuery = new RelationshipQuery();
        relatedTopsQuery.outFields = ["*"];
        relatedTopsQuery.relationshipId = 0;
        relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
        wellFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
          console.log("related recs: ", relatedRecords);
          if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
            console.log("No related records for ObjectID: ", features[0].attributes.OBJECTID);
            return;
          }
          var fset = relatedRecords[features[0].attributes.OBJECTID ];
          var items = array.map(fset.features, function(feature) {
            return feature.attributes;
          });
          //Create data object to be used in store
          var data = {
            identifier: "OBJECTID",  //This field needs to have unique values
            label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
            items: items
          };

          //Create data store and bind to grid.
          store = new ItemFileReadStore({ data:data });
          grid.setStore(store);
          grid.setQuery({ OBJECTID: "*" });
        });
    }

enter image description here

  • 1
    your screenshot appears to display more in the grid than just an ObjectID for the feature related to the selected feeder. i'd recommend inspecting the actual relationshipQuery web request and response to make sure you're forming a valid request and receiving the appropriate response. – John Gravois Jun 24 '16 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.