I'm using Delphi 10.1, Firebird 2.5 with Firedac. I have 3 FDQuery, all with CachedUpdates = true, being 1 MASTER, and 2 detail. In bd, the FK points to the ID of the master table. In the application, mastersource, MasterField and IndexFieldName are filled in as this link .
I use a TFDSchemaAdapter, all 3 queries have the SchemaAdapter field pointing to FDSchemaAdapter1. Until then, it works, takes the key at the time of writing and stores it in the two query detail. However, using the code below to save permanent in the bd, the first attempt it fires error (1 error for each line in the details), and worse: recording continues in the MASTER table, and does not record anything in any of the 2 details.
Then, I close the form, remaining with the application open, open the form again, put new data in all 3 query, and when I trigger the code below, it works as expected, firing 0 error, and it works ok all the others times.
No error is triggered when I give append, insert, post.
Where am I going wrong?
//Código do botão para salvar
dm.FDConnection1.StartTransaction;
iErrors := FDSchemaAdapter1.ApplyUpdates;
if iErrors = 0 then
begin
ShowMessage('não deu erros: '+IntToStr(iErrors));
FDSchemaAdapter1.CommitUpdates;
dm.FDConnection1.Commit;
end else
begin
MsgBxErroWarn('Deu erro: '+IntToStr(iErrors));
dm.FDConnection1.Rollback;
end;