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<String, Object>> loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = LoadRelationsQueryBuilder.ofMap();
loadRelationsQueryBuilder.setRelationName( "friends" );
Synchronous call:
String parentObjectId = // removed for brevity
List<Map<String, Object>> friends;
friends = Backendless.Data.of( "Person" ).loadRelations( parentObjectId, 
                                                         loadRelationsQueryBuilder );
for( Map friend: friends )
  Log.i( "MYAPP", friend.get( "email" ));
Asynchronous call:
String parentObjectId = // removed for brevity
Backendless.Data.of( "Person" ).loadRelations( parentObjectId,
        loadRelationsQueryBuilder,
        new AsyncCallback<List<Map<String, Object>>>()
        {
          @Override
          public void handleResponse( List<Map<String, Object>> friends )
          {
             for( Map friend: friends )
               Log.i( "MYAPP", friend.get( "email" ));
          }

          @Override
          public void handleFault( BackendlessFault fault )
          {
             Log.e( "MYAPP", "server reported an error - " + fault.getMessage() );
          }
        } );
Prepare LoadRelationsQueryBuilder:
LoadRelationsQueryBuilder<BackendlessUser> loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = LoadRelationsQueryBuilder.of( BackendlessUser.class );
loadRelationsQueryBuilder.setRelationName( "friends" );
Synchronous call:
String parentObjectId = // removed for brevity
List<BackendlessUser> friends;
friends = Backendless.Data.of( Person.class ).loadRelations( parentObjectId, 
                                                             loadRelationsQueryBuilder );
for( BackendlessUser friend: friends )
  Log.i( "MYAPP", friend.getEmail() );
Asynchronous call:
String parentObjectId = // removed for brevity
Backendless.Data.of( "Person" ).loadRelations( parentObjectId,
        loadRelationsQueryBuilder,
        new AsyncCallback<List<BackendlessUser>>()
        {
          @Override
          public void handleResponse( List<BackendlessUser> friends )
          {
             for( BackendlessUser friend: friends )
               Log.i( "MYAPP", friend.getEmail() );
          }

          @Override
          public void handleFault( BackendlessFault fault )
          {
             Log.e( "MYAPP", "server reported an error - " + fault.getMessage() );
          }
        } );