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:

LoadRelationsQueryBuilder *queryBuilder = [[LoadRelationsQueryBuilder alloc] initWithEntityClass:[BackendlessUser class] relationName:@"friends"];

DataStoreFactory *dataStore = [Backendless.shared.data of:[Person class]];
[dataStore loadRelationsWithObjectId:@"XXXXX" queryBuilder:queryBuilder responseHandler:^(NSArray *friends) {
    NSLog(@"Friends: %@", friends);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let queryBuilder = LoadRelationsQueryBuilder(entityClass: BackendlessUser.self, relationName: "friends")

let dataStore = Backendless.shared.data.of(Person.self)
dataStore.loadRelations(objectId: "XXXXX", queryBuilder: queryBuilder, responseHandler: { friends in
    print("Friends: \(friends)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

LoadRelationsQueryBuilder *queryBuilder = [[LoadRelationsQueryBuilder alloc] initWithRelationName:@"friends"];

MapDrivenDataStore *dataStore = [Backendless.shared.data ofTable:@"Person"];
[dataStore loadRelationsWithObjectId:@"DataStoreFactory *dataStore" queryBuilder:queryBuilder responseHandler:^(NSArray *friends) {
    NSLog(@"Friends: %@", friends);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let queryBuilder = LoadRelationsQueryBuilder(relationName: "friends")

let dataStore = Backendless.shared.data.ofTable("Person")
dataStore.loadRelations(objectId: "XXXXX", queryBuilder: queryBuilder, responseHandler: { friends in
    print("Friends: \(friends)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})