Aurelius Firebird Master Detail

Good evening
I am setting a master detail relation between two firebird tables wiht the TAureliusDataset components by setting the "DatasetField" property.
I saw that the detail table is linked to the master one through the "self" field and not on the "ID" field.
When I append a new record on the detail table, the master ID is not automatically reported on the detail table and if I manually insert the value of the "self" field of the master table I get this error "cannot turn persistent object of class TDETAILTABLE with id 0,41. The object is alredy in the persistent context "

regards

You should never modify the Self field in the dataset. Also, there is no way to link the detail to master by any field. I'm not sure what do you mean by "linked to the master one through the "self" field and not on the "ID" field.". Can you please provide more information, preferable a compilable project that reproduces the issue?

Demo.zip (149.6 KB)

Ok i send you a Demo that reproduce my problem. The problem raise when i Post the record on the first detail table, for the second detail table everything works

Regard

There are a couple of issues with your code. First, Self and ID_CASO fields are entity fields. Thus you should not use this code:

procedure TForm9.IBCasoDetNewRecord(DataSet: TDataSet);
begin
  IBCasoDet.FieldByName('ID_CASO').AsInteger:= IBCaso.FieldByName('Self').AsInteger
end;

procedure TForm9.IBCasoDetSClinNewRecord(DataSet: TDataSet);
begin
  IBCasoDetSClin.FieldByName('ID_CASO').AsInteger:= IBCaso.FieldByName('Self').AsInteger
end;

But instead, you should do this:

procedure TForm9.IBCasoDetNewRecord(DataSet: TDataSet);
begin
  IBCasoDet.EnittyFieldByName('ID_CASO').AsObject := IBCaso.EntityFieldByName('Self').AsObject;
end;

procedure TForm9.IBCasoDetSClinNewRecord(DataSet: TDataSet);
begin
  IBCasoDetSClin.FieldByName('ID_CASO').AsObject := IBCaso.FieldByName('Self').AsObject;
end;

Second, your entity TDETCLINICA has a composite ID:

  [Entity]
  [Table('DETCLINICA')]
  [Id('FID_DETCASO', TIdGenerator.IdentityOrSequence)]
  [Id('FID_CASO', TIdGenerator.None)]
  TDETCLINICA = class
  private
    [Column('ID_DETCASO', [TColumnProp.Unique])]
    FID_DETCASO: Integer;

In this case, FID_DETCASO will not be generated automatically, and that's why you get a "0" in the error message. You have to provide the correct IF_DETCASO value manually, or then remove the FID_CASO field from the ID.

Thanks a lot for the answer. Now I understand what the problem was. Is there a way with Aurelius to know the last value of a field's generator? and set a new value for it? Or do I have to manually query with Statement.ExecuteQuery?

regards

If the entity is defined with an ID of IdentityOrSequence, Aurelius will retrieve it automatically for you and put it in the identifier field of the class. If you mean you want to do a select from the database generator (sequence), then you indeed have to execute a direct SQL query.