Correct way to implement master detail editing

Hi, I am trying to find the correct way to create something like an order entry with orderlines. I want to be able to create the complete order before  submitting it to the database. In short: Case 1 Add new order Add orderlines Save the order with orderlines   Case 2 Open existing order Change orderlines Add orderlines Delete orderlines Save all changes   Case 3 Same as Case 2 But: Cancel all changes (original order should still be in the database)   I am unable te finde the correct way i.e. not changing the records in the database until it is all saved. I am relative new to Mendix so I might be overseeing some functionality, any advise/help is appreciated !
1 answers

Hi Martin,

For all cases:

Setup an order entity with 2 associations from orderline to order. The first is the regular one, the second is the asocation to delete, so could be called something like Orderline_Order_ToDelete.

Case 1:

You create a new order. You open a page in this context and create a datagrid over assocation to display orderline objects.

You can use the default create button(which automatically sets the association) to add a new orderline to your order. Use a custom microflow when saving orderline changes to prevent a default commit is executed when you save the orderline(and prompting a (auto)commit of the parent order object as well).

When finally saving the order you use a custom microflow to save, first commit the order and then retrieve the orderlines over association and commit the list as well.

Case 2:

Same as above, open page in order context. When editing the orderlines make sure you don't commit them. When deleting them use a custom microflow and set the assocation Orderline_Order_ToDelete and empty the other relation.

Refresh the orderline object when making this change and this make sures that only the active orderline objects are shown in your datagrid over assocation(from case 1). When saving the order retrieve all object in the Orderline_Order_ToDelete over asocation(not commited to db yes so you can only use assocation). Then all items in this list and after this commit the the order object and retrieve all orderlines over assocation and commit this list as well.

Case 3:

When canceling the above actions, make sure you rollback both order object and all orderlines. Make sure you retrieve orderlines over asocations so that you rollback both existing items(if any) and new items. Also retrieve the list over assocation to delete and rollback all items in this list as well by iterating over it and executing the rollback. Last, rollback the order item.

Hope this helps.