XDataClient cannot insert detail records

Hi,
Following Aurelius manual example about Master/Detail associations  using dataset fields, I had build a simple working sample and trying to post changes using XClient operations to Xdata server with POST, PUT and DELETE operations.

My Master Class uses a   [ManyValuedAssociation([], CascadeTypeAllRemoveOrphan)] for joining the detail Class, and I implement OnCreateObject, onObjectInsert, OnObjectUpdate, onObjectRemove handlers on the master aurelius dataset for XDataClient operations.

I was Insert One Master record in master dbgrid and One Detail record in a detail dbgrid, giving by hand the master primary key and in detail record his own primary key and for the relation with the master record the masterkey.

On the POST operation the result was that only a new Master record was inserted in the DB ignoring the one detail but without any error message.

I try to recall by XDataClient.List my previous inserted master record on the Grid and trying to insert again the detail with PUT operationthis time. In that case I get  the message "OPF Internal Error: Cannot merge of Type <MyDetailClass>. Object with ID <value of My new ID> does not exist.

I try to manually insert one detail record on the database  and I repeat my test to delete the master  record with xclient.DELETE operation. The result is successful and the master and detail record was deleted from db.

Last I recall the Master/ and detail recs on the grids and try to update again the existing master and detail records with Put operation on master. The result was that the master and detail was successful update.

My question is why XDataClient cannot insert new records on the detail Class with POST or PUT operations with already provided keys and only remove and update operations works as expected?

Thank you

Hi George, can you please provide the full mapping of the master and detail classes involved?

Two classes
---- the Master Class
 [Entity]
  [Table('ItemDocType')]
  [Id('FID', TIdGenerator.None)]
  TItemDocType = class
  private
    [Column('ID', [TColumnProp.Required])]
    FID: Integer;
    // some other fields   
    [ManyValuedAssociation([], CascadeTypeAllRemoveOrphan)]
    [ForeignJoinColumn('ItemDocTypeID', [TColumnProp.Required])]
    FItemDocTypeSeries: Proxy<TList<TItemDocTypeSeries>>;
    function GetItemDocTypeSeries: TList<TItemDocTypeSeries>;
  public
    constructor Create;
    destructor Destroy; override;
    property ID: Integer read FID write FID;
    property ItemDocTypeSeries: TList<TItemDocTypeSeries> read GetItemDocTypeSeries;
  end;

 -- the Detail Class
 [Entity]
  [Table('ItemDocTypeSeries')]
  [Id('FID', TIdGenerator.None)]
  TItemDocTypeSeries = class
  private
    [Column('ID', [TColumnProp.Required])]
    FID: Integer;
    // this is foreign key
  
    [Column('ItemDocTypeID', [])]
    FItemDocTypeID: Nullable<Integer>;

  public
    property ID: Integer read FID write FID;
    property ItemDocTypeID: Nullable<Integer> read FItemDocTypeID write FItemDocTypeID;
  end;
 
 

Hi George,


Please try to change the PostMode of your TXDataServerModule to Replicate:


  Module := TXDataServerModule.Create(...);
  Module.PostMode := TXDataPostMode.Replicate;
  Dispatcher.AddModule(Module);