Subscribe rss
Blog categories
All | Backendless features
Feature 12: Creating relationships between objects using developer console
January 18, 2015 by markpiller

In my post yesterday I 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 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 this post. Before you you create a relationship between any two objects, you need to make sure the objects are created first (this is an obvious thing, but if you are just getting started with Backendless), you see read about how to add objects using Backendless console.

In my example I have two tables: Restaurant and Location. You can see the schema of these tables below:

The Restaurant table schema:
restaurant-schemaThe 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:
  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 will be discussed in future posts.
Share this post
Tweet about this on TwitterShare on FacebookGoogle+