Correct, first new collection items are added, and then the removed items are deleted (or unassociated from parent).
If you want to make sure to first remove and then add, call hManager.Flush(hParent) right after extracting the item from the list.
In real we got an Entity like TParent putting Childs into an AureliusDataset.
The Dataset records are set by using SetSourceList.
There is no Manager attached to the dataset, so the changes will keep local.
That's necessary because we only want to save the changed data after pressing button Save.
Save will just save TParent with all changes appeared meanwhile within the Dataset.
That's why flush does not help, because new TChilds already appeared...
Are there any reasons why you first add new items before removing old ones?
Just tested:
Setting Unique Key to deferrable initially deferred will help if CascadeTypeAll is set.
But it won't help if CascadeTypeAllRemoveOrphan is set.
Historically, it's been always like this since version 1 released 10 years ago. Honestly, I don't remember right now why it was implemented like that, but I'm sure there were reasons.
We can't change it. What we could consider is a property in the manager that changes this behavior, so you can set it to modify the existing default behavior.
This doesn't make much sense to me, because in either case (deleting the record in case of RemoveOrphan or setting the FK to NULL in the case of "no" RemoveOrphan) the processing of removed items occur at the same time.
This would help me. So please provide such a property.
Same for me. I just wanted to check, if deferrable would help.
After I recognized, that it would be a fine solution, I recognized, that some orphaned Entities appeared here.
Next step I changed CascadeType for ManyValueAssociation to CascadeAllRemoveOrphaned and the Error occurs again.
Taking a look into the database, Unique-Key Definition did not change, so it's still deferrable initially deferred.