Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 21: Loading related data objects – the ‘auto-load’ approach
January 28, 2015 by markpiller
Spread the love

Previously I wrote a post on how to retrieve data objects from Backendless. The code in the article loads a collection of the Restaurant objects and although it does not show it, the related collection of the Location objects arrives un-initialized. That is the default behavior of Backendless when it comes to loading related objects. The code below demonstrates that the collection is indeed empty (null). (The code in these examples is from the article describing how to generate client-side code based on data tables).

Method to print out related locations:

Asynchronous example (Android and plain Java):

Synchronous example (plain Java):

The code output:

Method to print out related locations:

Asynchronous example:

Synchronous example:

Program output:

Asynchronous example:

Synchronous example:

Asynchronous example:

Synchronous example:

There are several approaches for loading related objects for a parent entity. This post reviews one of them – the ‘auto-load’ option. This option is available in Backendless console. The screenshot below shows the Restaurant table. Notice the ‘auto load’ checkbox in the “owner” and “locations” columns:
auto load checkbox - Feature 21: Loading related data objects - the 'auto-load' approach

When the checkbox is selected, Backendless automatically includes the related objects for the column into the response. If you select the auto-load checkbox for the “locations” column and re-run the code above, you will get the following output (JAVA example):

As you can see from the output, the related location for the “Cantina Laredo” restaurant has been loaded without making any changes to the code. All it took is the selected checkbox in the console.

Enjoy!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+