Backendless Support

Creating relationships between objects using developer console

Once a relationship between tables is in place, specific objects stored in the tables may be linked with each other. This linkage may be expressed through the code, where the instances of classes reference each other through the composition method. However, there are scenarios where these relationships may need to be created directly in the storage system. 

Backendless console is the development tool that offers a developer to manage it using a graphical interfaces. The types of relationships you can build by hand can be either one-to-one or one-to-many. As a result of establishing a relationship between any two or more objects, you can retrieve the related objects using the API. For instance, in the example below a restaurant object will have a relationship with one or more location. When the restaurant object is retrieved via an API call, all the related locations can be retrieved as well.

The example below is based on the tables and the relationship between them reviewed in the topic "Declaring relations between tables (classes) using developer console". Before a developer creates a relationship between any two objects, it is necessary to make sure the objects are created first (this topic is covered within the article "Adding objects using Backendless console").

In the example below there are two tables: Restaurant and Location. Consider the following schema:

The Restaurant table schema: 

The Location table schema: 

To create a relationship between a restaurant object and a location:

  1. Login to console, select an app and click the Data icon. 
  2. Select the Restaurant table and locate the locations column. If the instructions have been followed carefully (that is declared restaurant table, added a restaurant object and declared a relationship with the location table) , the restaurant table should look like this:
  3. Click the "plus" button for any of the restaurant objects. Backendless console displays a popup which can be used to find and add the related objects.
  4. Using the check boxes select the location objects which will be related to the restaurant and click the Add Related Objects button.
  5. Backendless saves the relation. The console also provides a way to navigate between the related objects and manage the relations - these features are overview within the correspondent Knowledge Base topics.

Review related topics:

Is article helpful?