Hello!
I have a similar situation to the situation, described here:
I read carefully the post, but I can't make it work
wdsOdvoz - master
wdsOdvozPodrobno - detail
In short, I open the master dataset and set $id=1, then I open the detail and fill it, also adding ref to each row. Upon saving I transfer the JSON to the master and save just the master.
Here is what I do:
I open the master (FOdvozId = 0 for new entries, >0 for editing an existing entry):
wdsOdvoz.Close;
wdsOdvoz.QueryString := '$filter=Id eq '+FOdvozId.ToString+' and Lokacija/Aktivna ne 0&$orderby=Id desc&$top=1&$expand=Podrobno/Posoda,Lokacija/Stranka,Vozilo/TipVozila';
wdsOdvoz.Load;
After that, I fill the master data:
procedure TfrmOdvoz.wdsOdvozAfterOpen(DataSet: TDataSet);
begin
wdsOdvoz.Edit;
TJSObject(wdsOdvoz.CurrentData)['$id'] := 1;
wdsOdvoz.FieldByName('Podrobno').Value := TJSArray.New;
...
wdsOdvoz.Post;
wdsOdvozPodrobno.Close;
wdsOdvozPodrobno.SetJsonData(wdsOdvoz.FieldByName('Podrobno').Value);
wdsOdvozPodrobno.Open;
end;
After that I fill the detail data:
It's al displayed correctly, but when I click "Save" on the GUI, IO get an 500 internal server error. Here's the code for saving:
if wdsOdvoz.State in dsEditModes then
wdsOdvoz.Post;
if wdsOdvozPodrobno.State in dsEditModes then
wdsOdvozPodrobno.Post;
wdsOdvoz.Edit;
wdsOdvoz.FieldByName('Podrobno').Value := TJSArray.New(TJSJSON.parseObject(TJSJSON.stringify(TJSObject(wdsOdvozPodrobno.CurrentData))));
wdsOdvoz.Post;
wdsOdvoz.ApplyUpdates;
My question is - what I'm doing wrong? I changed the code many times, but no success. I'm stuck and any suggestion would be appreciated.