How To Create An Entity Field
- To create a new entity field, navigate to the Entity screen.
- Click the Entities icon on the main menu (left toolbar) to reach the Entities page. Here you see all the entities in your application.
- Click on the Entity you want to edit, to get into the Entity's page.
- Click Add Field at the bottom of the list of fields.
- Fill the Display Name, and Name fields.
- Enter a description in the Description field.
- Click the toggle switch to activate or deactivate the Unique Field, Required Field, and Searchable settings.
- Select a Data Type from the drop-down list.
JSON is one of the supported data types. You can create JSON fields as part of your data model when creating an entity field. JSON enables you to create fields that store and include different kinds of data, making it easier for you to add custom fields to your applications. JSON can be used with both REST API and GraphQL.
Create Relation to Entity
- In the Data Type field, select Relation to Entity from the drop-down list.
- In the Related Entity field, select an entity from the drop-down list. A dialog box is displayed.
- Fill the Display Name, and Name fields.
- Click Create.
You might find it easier to first add all the fields you want, one after another, and only afterwards set the properties of each field.
White spaces are supported, which is useful when you want to enter a descriptive field name. The value is saved as the field’s display name. In addition to the display name, each field has an auto-generated Name that does not contain spaces or special characters. This name is later used for the API endpoint and in other places in the generated code. If needed, you can manually change the field name in the field's properties panel.
Searchable Setting
If the Searchable setting is not activated, the search cannot be based on the field. The field visibility is determined by the settings on the Permissions tab.
For example, if the customer's email address is visible (permissions set to All Roles for search), but the field is not set as Searchable the user will be able to search for customers by name, phone, or any other field but not by email address. However, the results will still include the email address.
Create Relation to Entity One-to-One
One-to-one relations refer to relations where at most one field can be connected on both sides of the relation.
In the following example below, we will configure a one-to-one relation between the User and Item entities.
- In the Data Type field select Relation to Entity
- In the Related Entity field enter the field to be related
- Select One “User” can be related to one “Item”
“User” and “Item” are used here as examples of field names. The names will reflect the names of the fields in your project.
- In the Foreign Key Holder field, select which side will hold the Foreign Key (”this side” or “other side”)
The Foreign Key will always be located in the selected field in the generated schema. The Foreign key can be only on one side, not both.
Significance of the Foreign Key
If, as in the above example, we have a User and an Item entity linked, and the Foreign Key is on the side of the Item, the Item cannot be created without a User. However, a User can be created without a Product.