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 Backendless.LoadRelationsQueryBuilder:
var loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = Backendless.LoadRelationsQueryBuilder.create();
loadRelationsQueryBuilder.setRelationName( "friends" );
Blocking call:
var parentObjectId = // removed for brevity
var friendsArray;
friendsArray = Backendless.Data.of( "Person" ).loadRelationsSync( 
                     parentObjectId, 
                     loadRelationsQueryBuilder );
friendsArray.forEach( function( friend ) {
  console.log( friend.email );
});
Non-blocking call:
var parentObjectId = // removed for brevity
Backendless.Data.of( "Person" ).loadRelations( 
        parentObjectId,
        loadRelationsQueryBuilder )
  .then( function( friendsArray ) {
      friendsArray.forEach( function( friend ) {
         console.log( friend.email );
      });
   })
  .catch( function( error ) {
    console.log( "server reported an error - " + error.message );
  });
Prepare Backendless.LoadRelationsQueryBuilder:
var loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = Backendless.LoadRelationsQueryBuilder.create();
loadRelationsQueryBuilder.setRelationName( "friends" );
Blocking call:
var parentObjectId = // removed for brevity
var friendsArray;
friendsArray = Backendless.Data.of( Person ).loadRelationsSync( 
                     parentObjectId, 
                     loadRelationsQueryBuilder );
friendsArray.forEach( function( friend ) {
  console.log( friend.email );
});
Non-blocking call:
var parentObjectId = // removed for brevity
Backendless.Data.of( Person ).loadRelations( 
        parentObjectId,
        loadRelationsQueryBuilder )
  .then( function( friendsArray ) {
      friendsArray.forEach( function( friend ) {
         console.log( friend.email );
      });
   })
  .catch( function( error ) {
    console.log( "server reported an error - " + error.message );
  });