I am using two TXDataWebDataSet, a master/detail relationship, when I am inserting a new record in the master the table ID does not exist yet, when doing the relationship below the ID is reset and an error occurs saying that there is no ID zero ( 0).
How do I use master/detail when a new record is being inserted in master?
If the master doesn't exist, you cannot use @xdata.ref, because you still don't have the id.
You should create a property named PEOPLE which should contain a TJSArray of all the person objects.
Probably you are already doing that, so all you should not is to not set such PEOPLE@xdata.ref property.
The array is in the master dataset. If PEOPLE property is a list, then probably there is a property in the master dataset named PEOPLE which holds the array.
Yes, there is an example in XData demos folder, subfolder web\master-detail, demo EDProject.groupproj.
The demo is indeed different as it requires saving the master before adding the detail. To insert details together with data, you can do something like this:
But I can't set the ID in the master, the ID is a sequence in my Aurelius entity.
In XData I don't need that, I just send the Object with the Master and the Array of the Detail and Aurelius that is in charge of cascading the ID of the Master to the Details.
See that in my payload there is no Array with the Detail of ID_ENDERECO and ID_CLIENTE as the Object PESSOA_CATEGORIA.
When you want to do a Master/Detail where you have an Aurelius entity mapping its ManyAssociation with ID using sequence or autoincrement in WebCore you do the following:
procedure TFClienteEdit.cdsCrudNewRecord(DataSet: TDataSet);
begin
inherited;
cdsCrudID_CLIENTE.Value := TJSArray.new;
cdsCrudID_ENDERECO.Value := TJSArray.new;
end;
procedure TFClienteEdit.cdsCrudAfterScroll(DataSet: TDataSet);
begin
inherited;
if DataSet.State <> DsInsert then
begin
cdsCliente.Close;
cdsCliente.SetJsonData(cdsCrudID_CLIENTE.Value); //cdsCrudID_CLIENTE is my ManyAssociation in Aurelius
cdsClient.Open;
cdsAddress.Close;
cdsAddress.SetJsonData(cdsCrudID_ENDERECO.Value); //cdsCrudID_ENDERECO is my ManyAssociation in Aurelius
cdsAddress.Open;
end;
end;
The key point is here, the passage from the Array that is in your Detail DataSet to the Array that is in the Master
procedure TFClienteEdit.btSaveClick(Sender: TObject);
begin
if cdsCliente.State in dsEditModes then
cdsCliente.Post;
if cdsEndereco.State in dsEditModes then
cdsEndereco.Post;
//This is the key point
cdsCrudID_CLIENTE.Value := TJSArray.new(TJSJSON.parseObject(TJSJSON.stringify(TJSObject(cdsCliente.CurrentData))));
cdsCrudID_ENDERECO.Value := TJSArray.new(TJSJSON.parseObject(TJSJSON.stringify(TJSObject(cdsEndereco.CurrentData))));
inherited;
end;