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 find
or 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( "XXXX-XXXX-XXXX-XXXX", {
relations:["relationA", "relationB"] })
.then( function( result ) {
})
.catch( function( error ) {
});
var obj = Backendless.Data.of( "TABLE-NAME" ).findByIdSync( {objectId:"XXXX-XXXX-XXXX-XXXX",
{ relations:["relationA", "relationB"] } } );
Non-blocking call:
Backendless.Data.of( DataTypeX ).findById( {objectId:"XXXX-XXXX-XXXX-XXXX",
loadRelations:"relationA,relationB" })
.then( function( result ) {
})
.catch( function( error ) {
});
var obj = Backendless.Data.of( DataTypeX ).findById( {objectId:"XXXX-XXXX-XXXX-XXXX",
loadRelations:"relationA,relationB" } );
Retrieving a collection of objects with relations¶
var queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setRelated( [ "RELATED-PROPERTY-NAME",
"RELATED-PROPERTY-NAME.RELATION-OF-RELATION" ] );
Then load data using the constructed queryBuilder
object with:
Non-blocking call:
Backendless.Data.of( "TABLE-NAME" ).find( queryBuilder )
.then( function( objectCollection ) {
})
.catch( function( error ) {
});
var objectCollection = Backendless.Data.of( "TABLE-NAME" ).findSync( queryBuilder );
Non-blocking call:
Backendless.Data.of( DataTypeX ).find( queryBuilder )
.then( function( objectCollection ) {
})
.catch( function( error ) {
});
var objectCollection = Backendless.Data.of( DataTypeX ).findSync( queryBuilder );
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 Backendless.DataQueryBuilder class. The class is used to identify related properties for relation retrieval. |
TABLE-NAME |
Name of the table where the data should be retrieved from |
DataTypeX |
Reference to a class/function which identifies a table where the data should be loaded from. |