Changing parent in a detail record causes an error in a lazily loaded screen

I was trying to change parent in a detail (child) row in a master-detail screen. The parent could be changed by a dropdown field in the child row.

I was expecting the child row to be changed and then it disappeared after saving the form.

Instead I’ve got the following error: Server error occurred. Please check server log for more details:
ForeignKeyConstraint FK_LogisticsRouteSchedule requires the child key values (xxxxx) to exist in the parent table.

how to replicate:

  1. checkout repository with a new version of demo model, the following branch
    GitHub - origam/origam at changing-parent-2022-4

  2. go to Menu > Widgets > Sections > Master Detail with a parent column

  3. it’s necessary to have at least 2 master records and at least one child record in the first parent

  4. go to the first master record and edit the child record’s parent column so that it point into the second master record. You get the error.

Fix to this problem is some what complicated. The exception is thrown here:

The problem is that the row’s dataset only contains the original parent row but not the new one.

Solution one:
add row.Table.DataSet.EnforceConstraints = false; before the line 1747 does fix the problem but it does not look like something we want to do.

Solution two:
load the missing row into the dataset. This would contradict the idea behind the lazy loaded screen. So probably not a good idea either.

This issue will be on hold until we can consult @tvavrda.

From my point of view, I don’t see any problem to load the other master record, since it’s needed. It’s the point of lazy-loading - load it when it’s needed, isn’t it?. So I would go with solution 2.

The current implementation works with only one master record in memory.

Implementing support for loading second master record doesn’t seem to be a matter of simple adjustment of the current code and could have an impact on other things.

This would be too much for such a specific use case. I would solve it by an action button that would offer a dialog for choosing another parent record and then load/update/save workflow to save it directly in the db. Then set the action button to RefreshAfterReturn: ReloadActualRecord so the updated record would disappear from the current screen.