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:
- Login to console, select an app and click the Data icon.
- 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:
- 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.
- Using the check boxes select the location objects which will be related to the restaurant and click the Add Related Objects button.
- 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:
- how to declare relationships between tables
- instances of classes reference each other through the composition method
- Declaring relations between tables (classes) using developer console
- Adding objects using Backendless console
- declared restaurant table
- added a restaurant object
- declared a relationship with the location table