Connect Mendix With REST-DB for Backup

Part 1

Max Bareis
The Startup
4 min readDec 8, 2020

--

Inspired by the article of Minke Van Dooremalen in Mendix Community, I was looking for a simple solution to backup my data from the sandbox projects to an external database. The simplest way to serialize objects in Mendix is to convert them to JSON or XML. JSON can be stored anywhere in textfiles or even in string attributes of databases. So I chose to use an easy to configure, web/cloud-based free of charge solution to store the small amounts of data I have. But before we define the storage, we first create the problem domain.

The Data Model

For this example we just need a simple Data Model with an address and a person with an address as a relationship:

An address may be eligible for many persons, but for the scope of this project a person should only have one address, so we design the association as one to many from Person.

OutputAsLabel should be the first entry, I will stress this later.

OutputAsLabel is a String that shows street zip and city. It is calculated in a microflow called before commit event of Address (Thanks Rene van Hofwegen for the hint not to use after commit event):

You might say, why not calculate directly?

The question calculate or store depends on two characteristics of the attribute:

A: How often will the attribute be changed?

B: How often will the attribute be called?

If B > A you should store the value. Otherwise if A > B you should calculate the value, as the microflow will be called less often.

In our case it is pretty simple to decide. The address will be created once and possibly not change because if a Person is moving to another address the new address is created, but the old still exists and will not be changed. So we will have only one microflow call to generate OutputAsLabel.

Next we need some simple overview pages to fill the content. For this we use the right mouse click on one of the entities and select Generate Overview Pages

Select also the other entity, choose the layout for overview and popup pages and press ok. There should be five new elements in your module. Two overview pages for address and person, Two newEdit pages also for address and person, and a Entity_Menu Snippet:

Coming back to above note, that OutputAsLabel should be the uppermost attribute: open the Person_NewEdit and look at the value that is used as selection label:

Automatically created DataViews with referenceSelectors always use the first attribute of the entity.

Now open the PersonOverview page and note that only FirstName and LastName have been added to the grid. The address is not there. I do not know why mendix isn’t adding them per default, if you know, please leave a comment below.

Select the last column and right click to add column right. Doubleclick the new column and choose OutputAsLabel attribute of Address reference:

Now distribute the columns to give the address more space:

Make sure the pages are accessible through your navigation. In this example we add both overview pages as subitems to a Database navigation item:

Start the server and add some entries to your database:

Now the first part of the journey is finished. We have a small DataModel with Overview pages and some entries. Time for Part 2 — Create a free Database in REST-DB.

> Part 2

--

--

Max Bareis
The Startup

Full Stack Developer. Building digital things from the early 90s until now. Currently focused on low code development.