Blog

How to Create Relationships Between Objects Using Backendless Console

by on April 1, 2020

Previously we showed how to declare relationships between tables. Once a relationship 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 lets you manage it using a graphical interface.

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 locations. 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 this post. Before you create a relationship between any two objects, you need to make sure the objects are created first (this may seem like an obvious thing, but if you are just getting started with Backendless, it can get lost in the shuffle), you see read about how to add objects using Backendless Console.

In our example, we have two tables: Restaurant and Location. You can see the schema of these tables below:

The Restaurant table schema:

Restaurant Table Schema

The Location table schema:

Location Table Schema

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

  1. Login to Console, select your app and click the Data icon.
  2. Select the Restaurant table and locate the locations column. If you followed the instructions (that is declared restaurant table, added a restaurant object and declared a relationship with the location table), your restaurant table should look like this:
    Restaurant Table locations Column
  3. Click the “plus” button for any of the restaurant objects. Backendless console displays a popup that can be used to find and add the related objects.
  4. Using the checkboxes, select the location objects which will be related to the restaurant and click the Add Related Objects button.
    Set Related Objects
  5. Backendless saves the relation. The Console also provides a way to navigate between the related objects and manage the relations – these features are discussed in other Recipe posts.

Leave a Reply