Creating a new relation

Some terminology

A relation is a data type representing a business relation between two types. 
  • Label - name of the endpoint in this relation.
  • Multiplicity - Defines the multiplicity constraints for the endpoints in the relation.
This terminology will become much more clear with an example.

Take the example of a parent relation between two user types. Here both endpoints of the relation are of type user. However one endpoint represents the parent and the other endpoint represents the child. In terms of the multiplicities, one parent may be associated with many children however, one child may be associated with only one parent. The diagram below indicates this setup.

Creating a new relation from the designer

  1. Go to the designer - Select your app from the apps list. To go to the designer view select the model designer option under the build and deploy section in the modulesOn clicking on the model designer you will be taken to the graph visualizer. The screenshot below shows the specific sections. Note that the actual content of types, relations may differ from what is shown in the image vs your app. 

  2. Create relation - You should be able to see the create type and relation icons on the top left on the graph designer. In this tutorial we are assuming that the types needed for the relation you want to create are already created. Let's say that you want to create a relation between a user and a note of type author

  3. Select types- Click the create relation button. It will get highlighted in blue to indicate that you are creating a relation. Next click on the two types between which you want to create a relation. In this case we will select note and user. If you want to create a relation between the same type e.g., friend between user and user, simply click on the user types twice. On each click, the selected types will get highlighted to indicate the selection.

  4. Provide a relation name - On selecting the two types, you will be shown a create relation screen confirming the selected types and asking for the name of the relation. Enter the name of the relation and click create relation as shown in the screenshot below. As of now a many-to-many relation has been created between the two types.

  5. Customizing the relation - The designer should now indicate a relation between the two types indicated as a line between the two types. By default this relation is a many to many relation, however we may want to customize it. To do that, click on the relation to display the relation name. Click on the relation name to open the relation details. 

    The relation details view shows the structure of the relation with the types involved. Click on any endpoint to open its definition. In our example, clicking on the note endpoint shows its details including its multiplicity definition and label. Here one note should only be associated with one user, so we can change the multiplicity to 1 instead of *. The label defaults to the name of the type and can be changed to whatever you need. Click save to apply modifications to the relation definition. You will see that the visual representation appropriately changes to indicate the new multiplicity. Click close to return to the designer view.

  6. Applying our changes - All new additions and updates made on the designer are temporary and only get applied to your app backend definition on clicking publish at the bottom. Now that we have created our new relation, click on publish to apply your changes to your app. You will be able to see the progress as this is happening and on completion you can verify that the changes have been applied to your app. Great! You have just created a new relation. 

Some important things to note

  1. All additions and modifications of types and relations on the designer are temporary and only applied to the app on clicking publish. 
  2. Relation modifications on endpoint names and multiplicities can only be made before the changes are applied to the app. After application, this information cannot be modified.