The Mendix app consists of modules. A module is a unit that divides functionality of your app into separate parts. By default, you have one module in Studio called MyFirstModule.
Each module has its own domain model. The domain model is a data model that describes the information in your application domain in an abstract way. It is central to the architecture of your application.
The domain model in Studio consists of the following:
Let us say you have a collection of CDs like the one in the table below:
|How to Dismantle an Atomic Bomb||U2|
|Exodus||Bob Marley & The Wailers|
The rows in the table are CDs. So, a CD is an entity. A specific CD like “How to Dismantle an Atomic Bomb” of the band U2 is an object of the CD entity. That means that an object is a single instance of an entity. Characteristics like the “Title” and “Artist” are attributes.
To view the Domain Models of your app in Studio, click the Domain Models icon in the left menu bar of Studio.
After opening a domain model, you will see an overview of all entities, attributes, and associations. The complexity of your domain model depends on the complexity of your app.
The Auto Arrange option in the top-left corner groups and aligns entities by associations. Entities with no associations will be vertically aligned.
The domain model can contain the following components:
- Entity – represents a class of real-world objects; entities can have attributes
- Attribute – describes and/or identify the entity
- Association – describes a relation between entities
2.1 Entities and Their Types
An entity represents a class of real-world objects, such as customers, invoices, work items, etc. If we draw a parallel with databases, the entity is a table.
You can add different type of entities to your domain model:
- Entity – an entity that can have attributes, associations, and represents a class of real-world objects.
- Image Entity – a special type of entity that allows you to store an image. For example, on pages, users will be able to view and upload images with the help of an image entity.
- File Entity – a special type of entity that allows you to store a file. For example, on pages, users will be able to upload and download files (such as, a text document, a pdf, a spreadsheet) with the help of a file entity.
- Workflow Entity – a special type of entity that is used as a context for a workflow.
- External Entity – only available if you have the Data Hub functionality enabled for your organization. For more information on external entities, see Data Hub in Studio.
2.2 Entity Properties
Entities have the following properties:
General properties define the name of the entity and its persistability:
Name – defines the name of the entity
Persistable – defines whether objects of the entity are stored in the database (for more information on persistability, see Persistability in the Studio Pro Guide)
Stored Information properties define whether the information about the entity is stored in the database. If the information is stored, it can be retrieved afterwards and can be used in page filters. For example, you can add a filter and show only objects that were created by the current user.
You can toggle the following properties:
Store ‘Created by’ – when enabled, the user who created the entity is stored in the database
Store ‘Creation Date’ – when enabled, the date and time when the entity was created is stored in the database
Store ‘Last Changed by’– when enabled, the user who was the last to make changes to the entity is stored in the database
Store ‘Last Changed Date’ – when enabled, the date and time when the entity was last changed is stored in the databaseYou cannot toggle Stored Information properties for Image, File, and Workflow entities.
Attributes are characteristics that describe and/or identify the entity. For example, a Customer entity typically has attributes for the name of the customer, an e-mail address, and other personal information. If we draw a parallel with databases, the attribute is a column.
For more information on attribute types and their properties, see Attributes.
An association describes a relation between entities. In the domain model, an association is represented by a line between two entities. If we draw a parallel with databases, the association is a foreign key.
For more information on association types and their properties, see Associations.
3 Adding New Entities
You can add new entities in the Toolbox.
To add an entity, do the following:
Open the Toolbox tab of the domain model.
Choose the entity type you would like to add, and drag and drop it the working area.
Fill out the name for the entity and click Create:
The new entity is added to the domain model.
3.1 Adding New Image or File Entities
While adding new entities from the Toolbox works for all types of entities, you can use a specific way of adding image and file entities to your domain model.
For example, you have an entity named Laptop and you want to be able to show users a specific image depending on the laptop model. In this case, you need to create an image entity (for example, named Product_Image). However, to get data and dynamically show the right image per laptop model, the Product_Image entity should also have a specific connection (an association) to the Laptop entity. For more information on associations and their types, see Associations.
To create a new image/file entity with an association automatically, follow the process described below:
Select an entity of the Entity type that will have a connection to the new image or file entity.
Click New attribute button.
In the Create New Attribute dialog box, click Add image or file in the bottom-right corner:
In the Image and Files dialog box, select the type or entity (image or file).
In the Create New Image/File Entity dialog box, specify the name of the special entity and click Create.
The new image or file entity is created with default Name and Size attributes and the association to the entity that you selected in the first step:
4 Adding New Attributes
To add attributes in the domain mode, do the following:
Select a block with entity you want to add an attribute to. The New attribute option appears:
Click New attribute and specify its Name and Type:
A new attribute is added to the entity.
5 Adding New Associations
There are several ways to add an association in the domain model. You can do one of the following:
Click the dot icon that appears and do one the following:
To create an association with an existing entity, drag the dot to the second entity.
To create an association with a new entity, drag the dot icon and hold it for a couple of seconds until it turns into a plus icon. By dropping the plus icon, you can create a new entity with an association from the first entity:
Select a block with an entity you want to add an association to do the following:
Click the arrow icon:
Select a second entity for the new association from the list of existing entities and click Select. You can also create a new entity for the association from the dialog box.
A module name is indicated next to the entity name in brackets.
If you select the entity from another module, you will create a cross-module association. For more information, see the Cross-Module Associations section in Associations. The entities of the current module are listed first.
6 Specifying Properties
In the domain model, you can manage the properties of entities, attributes, and associations on the Properties tab.
At the bottom of the tab you can see the Delete button.
6.1 Specifying Entity Properties
You can manage the following properties of an entity:
The Name of the entity
Persistability of the entity
To change the entity properties, click the entity in the domain model. The Properties tab for the selected entity is displayed automatically.
6.2 Specifying Attribute Properties
You can manage the following properties of an attribute:
- The Name of the attribute
The Type of the attribute
To change the attribute properties, click the attribute in the domain model. The Properties tab for the selected attribute is displayed automatically.
Fields that are displayed in Properties may vary depending on the type of the attribute.
Properties of Name and Size attributes of image and file entities are read-only, as in, you cannot edit them.
6.3 Specifying Association Properties
You can manage the following properties of an association:
- The Name of the association
- Multiplicity of the association
- The delete behavior of the objects
For more information, see Associations.
To change the association, click the line in the domain model. The Properties tab for the selected entity is displayed automatically.
If the association type is one-to-many or many-to-many, you can swap direction of it clicking the corresponding icon. For more information, see section 3 Multiplicity in Associations.
7 Deleting Entities, Attributes, or Associations
To delete an entity, attribute, or association, do the following:
Select the entity, attribute or association you want to delete.
Press Delete or click the Delete button at the bottom of the Properties tab.
You cannot delete Name and Size attributes of image and file entities.