In another article, we described how to load complex data objects from the persistent storage using the “auto-load” technique. Using that approach, a developer can statically identify specific (child) properties that should be returned along with the parent object(s) when a client app sends a request to load them.
That approach works well for object relations which must be unconditionally returned with the parent object. However, there are many scenarios when the client app must control which relations should be preloaded and returned along with the parent. The API described below allows you to accomplish that.
Consider the following example which uses the client-side code generated by Backendless based on the database schema. In that schema, the Restaurant table has the “locations” column which represents a one-to-many relationship between the Restaurant and Locations table. This means that a restaurant may have several related locations as shown in the screenshots below.
The restaurant objects:
The related location object for the “Cantina Laredo” restaurant:
Notice how the related locations column in set in the DataQueryBuilder class. Specifying the column name requests that the data objects referenced by the column must be initialized and returned with the every parent Restaurant object. The printLocations method displays the loaded Locations objects:
The code above produces the following output. Notice that the “Cantina Laredo” restaurant is fetched with the related location:
See the documentation for more information on loading related objects with the “one-step” approach.
Enjoy!