In a master detai relationship, is it possible to change a detail object, delete another detail object, include a new detail object, and use a single put (master) command to process all inclusions, changes, and deletions?
I can change a master object, change a detail object, include a new detail object, without problems, but deleting a detail object returns the following error:
Hello Miari, yes, it's possible. You didn't provide detailed information of your process (how are you exactly changing the master object, detail object and sending back to the server).
But I could suggest two things:
1. Recompile your server using
XDataModule.PutMode := TXDataPutMode.Merge;
or
Send a header
xdata-put-mode: merge
in your HTTP Request
2. Add TCascadeType.RemoveOrphan to the [ManyValuedAssociation] mapping of your detail objects. This will tell Aurelius that it should delete the detail object if it was removed from the list. Otherwise yes, an update will be performed because the detail object will not be removed (deleted) from the database, but simply be removed from the master (the foreign key will be set to null, but the detail object will still exist).
For changing it to CascadeTypeRemoveOrphan, you can use this specific code:
procedure OnManyValuedAssociationGenerated(Args: TManyValuedAssociationGeneratedArgs);
begin
case Args.CodeType.Name of
'TCultura':
case Args.Field.Name of
'FVariedadeList':
TCodeSnippetExpression(Args.AssociationAttr.Arguments[1].Value).Value := 'CascadeTypeRemoveOrphan';
end;
end;
end;