Mendix Client API: Prefetch a reference of a reference

1
Hello   I’m using the Mendix Cient API (https://apidocs.rnd.mendix.com/9/client/mx.data.html) for fetching entities.   Now I want to load an Entity A which has a reference to Entity B. Entity B has a reference to Entity C. Is it possible to do one mx.data.get Request which fetches Entities A with B and C already loaded?   I know that there is the option to pre fetch a reference with the filter: {references} option. Now I tried to pre fetch a reference of a reference. So that I have Entity A with data of B and C. With only one mx.data.get Request.   Example:   mx.data.get({ xpath: "//EntityA", filter: { references: [ [ReferenceToEntityB]: {}, [ReferenceToEntityB/EntityB/ReferenceToEntityC]: {} ] }, callback: function(obj) { obj.getChildren(ReferenceToEntityB).getChildren(ReferenceToEntityC) } });  
asked
1 answers
0

I’ve tried a lot of combinations, but it seems the client doesn’t allow the reference over reference. If I mimic your setup (I think):

The best I can come up with (that works, but isn’t a real single mx.data.get call) is:

mx.data.get({
	xpath: "//Test.EntityA", 
  count: true, 
  filter: {
    offset: 0,
    limit: 20,
    sort: [],
    references: {
      "Test.EntityA_EntityB": {}
    }
  }, 
	callback: function(EntityAList){
  console.log("Retrieved "+EntityAList.length+" object(s)");
    for(var i=0;i<EntityAList.length;i++){
      var EntityAChildren = EntityAList[i].getChildren("Test.EntityA_EntityB");
      console.log("Retrieving children of EntityA");
      console.log(EntityAChildren);
      for(var j=0;j<EntityAChildren.length;j++){
        console.log("EntityAChildren[j] GUID: " + EntityAChildren[j]);
        mx.data.get({
          xpath: "//Test.EntityB[id="+EntityAChildren[j]+"]", 
          count: true, 
          filter: {
            offset: 0,
            limit: 20,
            sort: [],
            references: {
              "Test.EntityB_EntityC": {}
           }
          }, 
          callback: function(EntityBList){
            console.log("Contents of EntityBList");
            console.log(EntityBList);
            for(k=0;k<EntityBList.length;k++){
              var EntityBChildren = EntityBList[k].getChildren("Test.EntityB_EntityC");
              console.log("Retrieving children of EntityB");
              console.log(EntityBChildren);
            }
          }
        });
      }
    }
  }
})



but you’d expect to be able to call the reference like:

mx.data.get({
	xpath: "//Test.EntityA", 
  count: true, 
  filter: {
    offset: 0,
    limit: 20,
    sort: [],
    references: {
      "Test.EntityA_EntityB": {},
      "Test.EntityA_EntityB/Test.EntityB/Test.EntityB_EntityC": {}
    }
  }, 
	callback: ....

Maybe it’s worth a try to make a support ticket out of it and either ask them to

  • properly document it why this cannot be done
  • document the way it’s supposed to work (with some good examples)
  • fix it, so it works as expected
answered