Skip to content

Single Step Retrieval

Important

Single 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.

This approach allows retrieval of a partial set of the related objects along with the parent object in a single findor findById request. Each relationship property (column) must be uniquely identified by name using the API documented below.

Retrieving a specific object with relations

Non-blocking call:
Backendless.Data.of( "TABLE-NAME" ).findById( 
                  String objectId, 
                  List<String> relations,
                  AsyncCallback<Map<String, Object>> responder )
Blocking call:
Map<String, Object> result = Backendless.Data.of( "TABLE-NAME" ).findById( 
                  String objectId, 
                  List<String> relations )
Non-blocking call:
Backendless.Data.of( T.class ).findById( 
                  String objectId, 
                  List<String> relations,
                  AsyncCallback<T> responder )
Blocking call:
T result = Backendless.Data.of( T.class ).findById( 
                  String objectId, 
                  List<String> relations )

Retrieving a collection of objects with relations

DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.addRelated( "RELATED-PROPERTY-NAME" )
queryBuilder.addRelated( "RELATED-PROPERTY-NAME.RELATION-OF-RELATION-PROP-NAME" );

// alternatively, you can use the addRelated method, which 
// accepts a collection of related column names:
List<String> relations = new ArrayList<String>();
relations.add( "RELATED-PROPERTY-NAME" );
relations.add( "RELATED-PROPERTY-NAME.RELATION-OF-RELATION-PROP-NAME" );
queryBuilder.addRelated( relations );

Then load data using the constructed queryBuilder object with:

Synchronous call:
List<Map> collection = Backendless.Data.of( "TABLE-NAME" ).find( queryBuilder );
Asynchronous call:
Backendless.Data.of( "TABLE-NAME" ).find( queryBuilder, AsyncCallback<List<Map>> callback );
Synchronous call:
List<T> collection = Backendless.Data.of( T.class ).find( queryBuilder );
Asynchronous call:
Backendless.Data.of( T.class ).find( queryBuilder, AsyncCallback<List<T>> callback );

where

Argument                Description
RELATED-PROPERTY-NAME name of a related property to load. For example, if table Person has a relation "homeAddress" pointing to an object in the Address table, the value would be "homeAddress". The syntax allows to add relations of relations. For example, if the same Address table has a relation "country" pointing to the Country table, then "homeAddress.country" would instruct the related Country object to be loaded as well.
queryBuilder an instance of the com.backendless.persistence.DataQueryBuilder class. The class is used to identify related properties for relation retrieval, paging, sorting and search with whereClause.
TABLE-NAME Name of the table where the data should be retrieved from.
T.class Reference to a class which identifies the table from which the data should be loaded from.