Helping you drive digital innovation
Subscribe
RSS Feed of the Mendix Blog
Thanks for Subscribing

Keep an eye out for Mendix resources coming straight to your inbox.

3 Simple Steps to Building Your Data Model in Mendix

on January 13, 2015

Share:

The data model is the foundation of your application; it is the equivalent of the underlying database tables. Mendix uses a default HQL databases for local testing. However, it can also use Microsoft SQL, PostgreSQL and Oracle databases, if you prefer.

You can define the following components directly within the domain model:

  • Entities: the equivalent of a database table with a unique key (i.e. a Location entity or Financial Transaction entity)
  • Attributes: the equivalent of the columns in a database table (i.e. the name and address in a location or the date and type of the financial transaction)
  • Associations: the equivalent of a table with the two unique identifiers joined between tables (i.e. an association of 1 customer and many orders)

In this post, I’ll explain each of the main components and how they contribute to creating your application. We’ll use a test case throughout this post – consider the product ordering application example below. You can walk through the example with us by signing up to try the product for free.

1. Define Your Entities

Whenever you start a new project, think of the entities or Objects that you need to create in order to build your application. In this example, we’ll build an application to allow customers to order their own products.

To create this application, you’ll have a customer, an order, an order line – which is the information entity keeping track of both the product and the order – and the product. Each entity results in a table in the database with a unique key. The diagram below showcases our four entities:

Define-Your-Entities

2. Add Your Attributes

After you have created your entities, you need to add more details to each entity (which is where attributes come into play). In our example, the customer might have a name or an account type such as VIP or general. The product might have a name or description.

As we fill out the entities, the details of the application will come to fruition. This system is incredibly helpful for developers who have to make adjustments or additions to the attributes mid project. It’s very easy to go back and add any other attributes that are needed. The diagram below illustrates how attributes are listed within our four entities:

Add Your Attributes

We added names, an auto generated order number, along with a date of when the order was placed. The attributes are the equivalent of table columns and have an attribute type and size such as string, integer, Boolean and all the typical data types you need to build the application.

3. Create Associations

After we have determined the entities and their attributes, it is time to determine how they are all related. In this example, a customer can have multiple orders, an order can have multiple order lines, and each product can be ordered multiple times. The figure below represents the relationship between the entities.

Create Associations

That sentence was a mouthful, but you will notice how the relationships are visually represented through the associations. You can see that the customer to order relationship is 1 to many (as indicated by the asterisk). To take this example one step further, we can also include delete behavior between the relationships.

For example:

If a customer has orders, should I delete all the orders associated with the customer (known as a cascading delete)?

OR

If a customer has orders, should we prevent the user from deleting an order (known as a prevention delete)?

Properties of Associations

Double click on the associations to see the behavior and how the delete option is configured. The delete behavior should depend on the business needs. Consider the following questions: Is it important to keep the customer when they have orders? Or it is more important to clean up the database and not have orphan orders when deleting customers?

These are good questions to ask the business users and will help craft the right business rules. The visual representation of this is either as blue (for prevention deletion) or red (for cascading delete).

[Related Content: Join Our Expert Webinar Series]

It’s Easy to Get Started, But Don’t Forget Security

The security of the application starts with the domain model, which is why these basic practices are so important to overall success. I go into greater depth on security best practices at this article. I strongly recommend that business engineers start implementing the modeler security on the domain first and then move onwards.

Questions? Did I forget to mention anything about the domain model? Anything I should cover more in depth in my next article? Let me know!

Subscribe to Our Blog

Receive Mendix platform tips, tricks, and other resources straight to your inbox every two weeks.

RSS Feed of the Mendix Blog
Daniela Field

About Daniela Field

Daniela has 7+ years of experience as a technology professional. She enjoys working with clients, understanding their business needs and offering solutions that move clients towards efficiency, productivity and profitability. She has worked with various Fortune 500 companies as well as privately held organizations. Her previous work was focused on enterprise data search, eDiscovery, document assembly and contract management. Currently, she is a Senior Solutions Consultant for the Mendix's Boston office. Daniela firmly believes that the use of Agile methodologies is the future in application development and enjoys the flexibility and speed with which applications can be developed and deployed using the Mendix Platform.

| Twitter