Master-detail Taureliusdataset

Hi, I have two classes automapped as "Entity" by aurelius framework. I added a
"ManyValuedAssociation" attribute so they are in master-detail relationship.
At the database level, aurelius has created two tables, one with a foreign key referencing id-field of master-table. All fields are signed as "not null", but if I create by code two objects, one for each class and I set some properties (not all), the manager saves the objects "correctly".But I should get an error at the database level as I don't set some required properties. Why this?
If I do the same thing using two taureliusdataset and try to insert a new detail row I get an error if I don't set all fields (properties); If I do that I get an error as the foreign key is not set (I expected the TaureliusDataset (master) to provide this value. Is there a way?).
Thanks

You didn't provide the source code, so I can only guess here.
But if you said classes are automapped and fields are created as not-null, that means your class field types are not Nullable, but simply the primitive type (Integer, string, etc.). That means the class cannot hold null values. If your Integer property is 0, it will save the value as 0, not null. So, all fields are being set.

For better diagnostics:

  1. Provide the source code of mapped classes
  2. Inspect the SQL command being executed by Aurelius.
  3. Check the values saved in the table fields in the database.

I guess the error is at dataset level. The field is marked as required, so if you don't type anything in the dataset, it asks for a value.

Please provide more details, if possible sample project reproducing the issue, etc.

This is my code :


  [AutoMapping]
  [Entity]

  TDima = class
  private
    FID : integer;

    FCodice: string;
    FPLabel: String;
    FCodiceParteCliente: string;
    FModello: string;
    FCodiceCliente: string;
    FNomeCliente: string;

    FDescrizione: string;
    FQtaRichiesta: integer;
    FQtaOttenuta: integer;
    FNFasiLavorazioni: byte;
    FLavorazioni: String;
    FPath: string;
    FArea: Double;
    FMateriale: string;
    FSpessore: string; // ShortString;
    FEnabled: boolean;
    FLastFileModify: TDate;
    FTag: integer;
    FAnteprima: TBlob;
    function FQtaRimanente: integer;
  public

    constructor Create; overload;


    Function GetNomeFile: string;
    Function GetMaterialeCompleto: string;
    procedure SetLabelBis(aBis: Char);




    property PLabel: string read FPLabel write FPLabel;
    property CodiceParteCliente: string read FCodiceParteCliente
      write FCodiceParteCliente;
    property Codice: string read FCodice write FCodice;
    property Modello: string read FModello write FModello;
    property CodiceCliente: string read FCodiceCliente write FCodiceCliente;
    property NomeCliente: String read FNomeCliente write FNomeCliente;
    property Descrizione: string read FDescrizione write FDescrizione;
    property QtaRichiesta: integer read FQtaRichiesta write FQtaRichiesta;
    property QtaOttenuta: integer read FQtaOttenuta write FQtaOttenuta;
    property Nfasilavorazioni: byte read FNFasiLavorazioni
      write FNFasiLavorazioni;
    property Lavorazioni: String read FLavorazioni write FLavorazioni;
    property QtaRimanente: integer read FQtaRimanente;
    property Path: string read FPath write FPath;
    property Area: Double read FArea write FArea;
    property Materiale: string read FMateriale write FMateriale;
    property Spessore: String read FSpessore write FSpessore;

    property Enabled: boolean read FEnabled write FEnabled;
    property LastFileModify: TDate read FLastFileModify write FLastFileModify;
    property Tag: integer read FTag write FTag;

    property Anteprima: TBlob read FAnteprima write FAnteprima;

  end;


  [AutoMapping]
  [Entity]

  TCommessa = Class
  Private

    Fid: Cardinal;
    FModello: string;
    FCodiceCliente: string;
    FNomeCliente: string;
    FBis: byte;
    FNote: string;
    FNProgramma: string;
    FAnno: String;

    Fname: integer;


    [ManyValuedAssociation([], CascadeTypeAllRemoveOrphan)]
    [ForeignJoinColumn('ID_COMMESSA', [TColumnProp.Required ])]
    FDime: TList<TDima>;



    function GetFatte: integer;
    function GetAvanzamento : Double;
    function GetTotalePezzi : integer;
    function GetPezziRimanenti : integer;
    function GetTotaleDime : integer;

  Public

    constructor Create;
    destructor destroy; override;



    property Id: Cardinal read Fid write Fid;
    property Modello: string read FModello write FModello;
    property CodiceCliente: string read FCodiceCliente write FCodiceCliente;
    property NomeCliente: string read FNomeCliente write FNomeCliente;
    property Bis: byte read FBis write FBis;
    property Note: string read FNote write FNote;
    property Nprogramma: string read FNProgramma write FNProgramma;
    property Anno: String read FAnno write FAnno;
    property TotaleDime: integer read GetTotaleDime;

    property Avanzamento : double read GetAvanzamento;
    property Fatte: integer read GetFatte;
    property PezziRimanenti: integer read  GetPezziRimanenti;
    property TotPezziFusto: integer read GetTotalePezzi;
    property Dime: TList<TDima> read FDime;

  End;

I use sqlite database with firedac.

If I set two TaureliusDataset with a master-detail relationship, when I add a new detail row (with all values), it seems there isn't a way to set value for the foreign key. I tried with the "onNewrecord" event but the field used for the foreign key doesn't exist (application level) even if is there in the table (database level).

this raises the error Field 'ID_COMMESSA' not found :

procedure TForm1.AureliusDataset2NewRecord(DataSet: TDataSet);
begin
    DataSet.FieldByName('ID_COMMESSA').Value := AureliusDataset1.FieldByName('ID').Value
end;

I created the fields with
"Load field definitions" procedure
but 'ID_COMMESSA' field is not there.
thanks

Correct, TAureliusDataset works are object level, not database level.
Thus, your class TDima doesn't have any reference to the TCommessa class. For that you should create do a bidirectional association, by adding the FCommesa field in TDima class and then modifying the ManyValuedAssociation to point to it, removing the ForeignJoinColumn attribute.

Some references:

Once you do that, you can set the parent object in OnNewRecord event by referencing the object, as showed here:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.