How to create an object along with its associated objects in a single form?

0
I have this domain model. Devices has-many alerts. I am able to create devices and alerts objects separately using a data view or data grid’s new button with inline editing, but they are not associated to each other. What I want is: 1) How to create a single form to create a device and add alerts to this device (create new alerts) and then save the device object and its associated alerts.  2) Is the foreign key required in alerts table? I see mendix uses a separate table for associations. How to create devices and alerts so that an entry is automatically made to that separate table? A sketch of desired result is below:
asked
2 answers
3

Hi there,

You can create a page with a DataView of Device first and then populate the DataView with macid and name.

Inside the DataView, you can create a DataGrid of Alert, using XPath

By doing so, you can view, create and edit the alerts that are associated with the device.

On the DataGrid, you can add two buttons: New Alert and Edit

New Alert button should call a microflow like below:

Change action is configured as below:

In this way, the new alert you save in Alert_NewEdit will have an association to the device.

The Edit button on DataGrid can also show Alert_NewEdit page to edit created alerts.

 

Your final result would look like this:

 

For your second question:

Mendix automatically handles the keys for you. So you don’t have to worry about managing keys. Also, the references between Device and Alert serves the function of foreign keys.

 

There may be a better way to do this, but this is what I can come up with currently. Hope this can help you!

 

Regards,

Jeremy

 

answered
2

Hi There,

An addition to the answer of Jeremy

Inside the DataView, add DataGrid of Alert, using database (XPath won't add anything in this situation; unless you need more advanced constraining)

Select over association (in case of using the XPath datasource, same applies)

By doing so, the list of alerts are constrained by the association.

New Alert button will automatically set the association between the device and the new alert. So NO need for an microflow to handle this

Regards, Rene

 

 

answered