A Model in itself is fairly easy to understand. When building an application, you’ll find Models often are connected or related to each other. If this is the case, you usually have to define the relationships between the Models.
There are two different ways to create model relations.
- Drag & drop
- Adding a relation in List view
Drag & drop
When clicking on Datamodel in the Builderbar you can make relations by simply drag & drop the arrow from one Model to the other.
Choose relation type
Pick the relation type of your choosing by clicking the save button:
- Belongs to
- Has many
- Has and belongs to many
More information about the relation types can be found here: What are the three relation types?
Adding a relation in list view
After opening a Model you can create new relations by navigating to its relations.
Clicking the Relations button opens your Model Relations panel.
< Close: Closes the Relations panel.
+New: Let’s you add a new Relation to your Model.
Questionmark [?]: By clicking this button, a new panel pops-up. This panel will present an instruction video on “HowTo create model relations?”
Search bar: In the search bar you can search through all of your Model Relations (when available) by Name, Label or Type.
Refresh: When your added/changed item doesn’t immediately appear in your panel hit the refresh button (or
R on your keyboard).
When adding Relations, you'll see 3 fieldsets, each containing their own subject:
Type: Select the relation Type (Belongs to, Has many or Has and Belongs to many relations from the current Model)
Model: Select the Model which you want the current Model to relate to.
Name: After selecting the related Model, the Name value will automatically get the same value as Model. You can change the Name value if necessary.
Name is used for database pruposes of your app.
Label: The Label value will automatically contain (a more readable version) of Name. If you want you can rename Label although it isn’t necessary.
Label is only used for your interfaces, for example columns or form components. The Label option is mostly used for a more (end)userfriendly value.
Default value: You can select a record of the related datamodel as default value, instead of selecting the value every time a record is created. For example, you can set the most used or recommended value to be the default value. It remains possible to select another value if necessary.
Only available when Type Belongs to is selected.
When Use value is clicked, the presented values are the Label properties of your selected Model. A value can be chosen in an autocomplete fashion or by a listing (the list has a limitation of 100 values maximum). Check the Model Reference for the available auto complete and Label property settings.
For more dynamic options, click the Use expression button and use expressions instead.
Apply default when blank: If the relation is left blank when a new record is created, the record set as Default value will automatically be chosen.
With this setting enabled, the property will be given the default value if left blank. If this setting is disabled, the property will be left blank if emptied before saving.
Inverse name: After selecting the related Model, by default, Inverse name will be filled with the name of the selected Model. You can change the name although it isn’t necessary. The Inverse name determines the opposite association from the related Model. So if the Relation is “Belongs to - Has many” the Inverse name shows the name of the “Has many - Belongs to”.
Condition: Apply a condition (filter) to narrow down the results. All properties and relations are available for filtering.
Only available when Type Has many is selected.
This fieldset is only available when a Belongs to relation is made. You can add custom expressions as validation of your Relation. Each validation can hold a custom error message. These messages will be shown to the end user if the validation fails in the back office and can also be accessed in an after_validation action.
This fieldset is only available when a Belongs to relation is made. The last fieldset will give you the option to add variables. These variables can be used for validation purposes only! For example, you need a certain value or object to use in a validation, but is not (yet) available in one of the existing Relations. By calculating this value in a variable you can create much more complex validations. Variables are only available for Relations where Validations are optional.