Hello,
I'm searching how I can retrieve master/detail dataset form client application to the server with datasnap and firedac components.
But I can't get it run properly. Do get data and update data thats working fine. But not for an insert of the data.
I will try to explain the problem.
On the client site we have a master/detail dataset. This is made with TFDMemTables. The CachedUpdates property is set to true. We did also set the poperties Indexfieldnames, Masterfields and MasterSource.
When we insert on the Master dataset de PK gets -1. Same for the Detail dataset on insert the PK get -1 and the relation ID between master/clients gets the same as the PK of the master. Everything ok on the client side.
When I want to apply this to the server I can't apply the detail data because it doesn't recognize the PK -1.
I use the Data.FireDACJSONReflect unit
Code from client to server to send the data:
procedure TForm2.SendToServerClick(Sender: TObject);
var
DeltaList: TFDJSONDeltas;
begin
if mmtMaster.State in dsEditModes then mmtMaster.Post;
if mmtDetail.State in dsEditModes then mmtDetail.Post;
DeltaList := TFDJSONDeltas.Create;
TFDJSONDeltasWriter.ListAdd(DeltaList, 'Master', mmtMaster);
TFDJSONDeltasWriter.ListAdd(DeltaList, 'Detail', mmtDetail);
FServerMethode.ApplyChanges(DeltaList);
end;
Servermethode fromm the server side:
function TServerMethods1.ApplyChanges(const aJSONDeltas: TFDJSONDeltas): String;
var
LApply: IFDJSONDeltasApplyUpdates;
begin
Result:= '';
// Create the apply object
LApply := TFDJSONDeltasApplyUpdates.Create(ADeltaList);
// Apply the master delta
LApply.ApplyUpdates('Master', FDQueryMaster.Command);
if LApply.Errors.Count = 0 then
// If no errors, apply the detail delta
LApply.ApplyUpdates('Detail', FDQueryDetail.Command);
if LApply.Errors.Count > 0 then
Result:=(LApply.Errors.Strings.Text);
end;
I get an error when I apply the detail. --> LApply.ApplyUpdates('Detail', FDQueryDetail.Command);
It conplaints about the relation key -1.
I search many demo about client/server with firedac and these shows only how to get and update the data but not how to insert data.
Can someone point me the right direction or demo with insert data (Master/Detail - Client/Server)?