I am trying to find how to get an object and all of its hierarchy of relations in the least number of queries. There are 4 levels of relations. The size of the relation objects are no more than 20 items, some objects may only have fewer than 10 and others more, but the Backendless limit for number of relations is a maximum of 10. So I have to iterate at each level through each child object and get all of its relations, which ends up being a lot of calls.
Is there a more optimal query that I could make to solve this problem?
Even if that is possible, does your app really show that much information on a single screen? I think any drive to minimize the number of calls is likely to yield a substandard user experience.
Mark, even with 2 levels of relations, say a single object has children objects who also have children objects. Is there a way to get this information with only 2 queries?
Yes, you’d reference the relations in a DataQueryBuilder object in the format of firstLevelRelation, firstLevelRelation.secondLevelRelation. Here’s an example with REST:
Doing it this way was what I originally had until I noticed I was only getting 10 objects back when I needed to get all 12. So that’s when I had to iterate through each object and get all of the children with the pageSize parameter.
That’s correct, this is the built-in behavior. Loading additional objects would require a separate API call. To minimize the number of calls from the client-side perspective, you could shift that logic to Cloud Code which would be responsible for iterating over the collection and loading additional child objects to build the entire tree.