Skip to content

Two Steps Retrieval

Important

Two Step Retrieval loads only a partial set of the related objects (default size of the retrieved related collection is 10). To load additional related objects, use the Relation Paging API.

With this approach a collection of related objects for a specific relation property in a parent object is retrieved from the server. The client application must know parent object's objectId. The API loads a collection of related children for one property at a time. Child objects retrieved in paged sets, see the Relation Paging API sectionfor additional details.

Suppose the Person table has a one-to-many relationship column friends pointing to the Users table. The code below retrieves related BackendlessUser objects for a specific Person object:

Prepare LoadRelationsQueryBuilder:
LoadRelationsQueryBuilder<Map> loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = LoadRelationsQueryBuilder.ofMap("friends");

String parentObjectId = // removed for brevity
Backendless.data.of("Person").loadRelations(parentObjectId, loadRelationsQueryBuilder).then((friends) {
  for (Map friend in friends) {
    print(friend['email']);
  }
});
Prepare LoadRelationsQueryBuilder:
LoadRelationsQueryBuilder<Person> loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = LoadRelationsQueryBuilder.of<Person>("friends");

String parentObjectId = // removed for brevity
Backendless.data.withClass<Person>().loadRelations(parentObjectId, loadRelationsQueryBuilder).then((friends) {
  for (Person friend in friends) {
    print(friend.email);
  }
});