Hi, I have a xData Rest server with a Echo server implemented. My VCL clients have Echo client implemented. All works as expected.
My question is about how to get already existing data from server to client at startup of clients.
At startup of client, but before I subscribe to Aurelius events, I go through every entity I need on the client and "replicate" it.
procedure TdmReplication.CopyExistingData;
var
lClient: TXDataClient;
lLocalConn: IDBConnection;
lLocalManager: TObjectManager;
begin
// LEO 12.12.2022: Get LOCAL connection and manager
lLocalConn := CreateConnection;
lLocalConn.Connect;
lLocalManager := TObjectManager.Create(lLocalConn);
// LEO 12.12.2022:
lClient := TXDataClient.Create;
try
lClient.Uri := 'http://tdwos/staweb/api';
DoReplicate<TProductGroup>( lLocalManager, lClient);
DoReplicate<TFirmware>( lLocalManager, lClient);
finally
lClient.Free;
lLocalConn.Disconnect;
lLocalManager.Free;
end;
end;
And this:
function TdmReplication.DoReplicate<E>(aManager: TObjectManager; aClient: TXDataClient): boolean;
begin
var lItemList := aClient.List<E>;
for var lItem in lItemList do begin
aManager.Replicate(lItem);
end;
end;
From the above one can see that I replicate the entities TProductGroup and TFirmware.
The TProductGroup replicates just fine. The TFirmware does not unfortunately. The TFirmware has an assosiation to TProductGroup like this:
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ProductGroupID', [TColumnProp.Required], 'ID')]
[ForeignKey('FK_Firmware_ProductGroup_ProductGroupID')]
FProductGroupID: Proxy<TProductGroup>;
function GetProductGroupID: TProductGroup;
procedure SetProductGroupID(const Value: TProductGroup);
When replicating TFirmware I get this error:
Project SmartStudioPro.exe raised exception class ESQLiteException with message 'NOT NULL constraint failed: Firmware.ProductGroupID'.
As the data is coming from the server, all data is valid. All records in TFirmware has a valid ProductGroupID (FK) value.
What I see debugging the code is that for a TFirmware item being replicated, the field TFirmware.ProductGroupID = nil, when it should not be nil.
Any hints or suggestion to what I'm doing wrong here?