Editing master record issue

d_DM0.zip (6.9 KB)

(NOTE : d_DM0.zip is a RAR archive)

In my DM unit attached i've a problem on master table when wdROrdAfterPost OR wdROrdAfterDelete fire Calc_RiepOrdine() that is a summaries of the operations that update the total amount with wdTOrd.FieldByName('Tot_Doc').AsFloat:=TotOrd; on master table.

My problem happen when i use DM0.SalvaAnnulla_Ordine(Azione:Word):TJSPromise; to save the master/detail table and i have an error showed in image.
If i exclude update total amount (wdTOrd.FieldByName('Tot_Doc').AsFloat:=TotOrd;) on the master table all go fine !!!

Can you help me ?

Please provide the full mapping of involved classes.

  [Entity]
  [Table('ORD_RISTO_T')]
  [Id('FPK_1', TIdGenerator.IdentityOrSequence)]
  TORD_RISTO_T = class
  private
    [Column('PK_1', [TColumnProp.Required])]
    FPK_1: Integer;

    [Column('CAUSALE', [], 3)]
    FCAUSALE: Nullable<string>;

    [Column('TIPO_DOC', [], 5)]
    FTIPO_DOC: Nullable<string>;

    [Column('VEN_POS', [TColumnProp.Required])]
    FVEN_POS: Boolean;

    [Column('DATA_DOC', [])]
    FDATA_DOC: Nullable<TDateTime>;

    [Column('NUM_DOC', [], 20)]
    FNUM_DOC: Nullable<string>;

    [Column('COD_PC', [], 5)]
    FCOD_PC: Nullable<string>;

    [Column('COD_OPER', [], 5)]
    FCOD_OPER: Nullable<string>;

    [Column('TIPO_SOGG', [], 3)]
    FTIPO_SOGG: Nullable<string>;

    [Column('COD_CLIFOR', [], 20)]
    FCOD_CLIFOR: Nullable<string>;

    [Column('COD_CLI_GFE', [], 20)]
    FCOD_CLI_GFE: Nullable<string>;

    [Column('RAG_SOC', [], 50)]
    FRAG_SOC: Nullable<string>;

    [Column('INDIRIZZO', [], 50)]
    FINDIRIZZO: Nullable<string>;

    [Column('CITTA', [], 50)]
    FCITTA: Nullable<string>;

    [Column('PROV', [], 5)]
    FPROV: Nullable<string>;

    [Column('CAP', [], 5)]
    FCAP: Nullable<string>;

    [Column('TELEF_1', [], 20)]
    FTELEF_1: Nullable<string>;

    [Column('TELEF_2', [], 20)]
    FTELEF_2: Nullable<string>;

    [Column('DEST_DIV', [TColumnProp.Required])]
    FDEST_DIV: Boolean;

    [Column('RAG_SOC_DIV', [], 50)]
    FRAG_SOC_DIV: Nullable<string>;

    [Column('INDIRIZZO_DIV', [], 50)]
    FINDIRIZZO_DIV: Nullable<string>;

    [Column('CITTA_DIV', [], 50)]
    FCITTA_DIV: Nullable<string>;

    [Column('PROV_DIV', [], 5)]
    FPROV_DIV: Nullable<string>;

    [Column('CAP_DIV', [], 5)]
    FCAP_DIV: Nullable<string>;

    [Column('TELEF_1_DIV', [], 20)]
    FTELEF_1_DIV: Nullable<string>;

    [Column('TELEF_2_DIV', [], 20)]
    FTELEF_2_DIV: Nullable<string>;

    [Column('PART_IVA', [], 20)]
    FPART_IVA: Nullable<string>;

    [Column('COD_FISC', [], 20)]
    FCOD_FISC: Nullable<string>;

    [Column('EMAIL', [], 50)]
    FEMAIL: Nullable<string>;

    [Column('TOT_ESENTE_IVA', [], 18, 4)]
    FTOT_ESENTE_IVA: Nullable<Double>;

    [Column('TOT_IMPONIBILE', [], 18, 4)]
    FTOT_IMPONIBILE: Nullable<Double>;

    [Column('TOT_IVA', [], 18, 4)]
    FTOT_IVA: Nullable<Double>;

    [Column('TOT_OMAGGI', [], 18, 4)]
    FTOT_OMAGGI: Nullable<Double>;

    [Column('TOT_EXTRA', [], 18, 4)]
    FTOT_EXTRA: Nullable<Double>;

    [Column('TOT_DOC', [], 18, 4)]
    FTOT_DOC: Nullable<Double>;

    [Column('TOT_RICEVUTO', [], 18, 4)]
    FTOT_RICEVUTO: Nullable<Double>;

    [Column('TOT_INCASSATO', [], 18, 4)]
    FTOT_INCASSATO: Nullable<Double>;

    [Column('TOT_RESTO', [], 18, 4)]
    FTOT_RESTO: Nullable<Double>;

    [Column('STATO_DOC', [])]
    FSTATO_DOC: Nullable<Integer>;

    [Column('DATA_ORA_ASP', [])]
    FDATA_ORA_ASP: Nullable<TDateTime>;

    [Column('NOTE_ASP', [], 100)]
    FNOTE_ASP: Nullable<string>;

    [Column('CMD_PK1', [])]
    FCMD_PK1: Nullable<Integer>;

    [Column('INIZIO_INS', [])]
    FINIZIO_INS: Nullable<TDateTime>;

    [Column('FINE_INS', [])]
    FFINE_INS: Nullable<TDateTime>;

    [Column('INIZIO_ESEC', [])]
    FINIZIO_ESEC: Nullable<TDateTime>;

    [Column('FINE_ESEC', [])]
    FFINE_ESEC: Nullable<TDateTime>;

    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FPK_1')]
    FORD_RISTO_R: Proxy<TList<TORD_RISTO_R>>;

    Function Get_ORD_RISTO_R: TList<TORD_RISTO_R>;
  public
    Constructor Create; Overload;
    Destructor Destroy; Override;

    property PK_1: Integer read FPK_1 write FPK_1;
    property CAUSALE: Nullable<string> read FCAUSALE write FCAUSALE;
    property TIPO_DOC: Nullable<string> read FTIPO_DOC write FTIPO_DOC;
    property VEN_POS: Boolean read FVEN_POS write FVEN_POS;
    property DATA_DOC: Nullable<TDateTime> read FDATA_DOC write FDATA_DOC;
    property NUM_DOC: Nullable<string> read FNUM_DOC write FNUM_DOC;
    property COD_PC: Nullable<string> read FCOD_PC write FCOD_PC;
    property COD_OPER: Nullable<string> read FCOD_OPER write FCOD_OPER;
    property TIPO_SOGG: Nullable<string> read FTIPO_SOGG write FTIPO_SOGG;
    property COD_CLIFOR: Nullable<string> read FCOD_CLIFOR write FCOD_CLIFOR;
    property COD_CLI_GFE: Nullable<string> read FCOD_CLI_GFE write FCOD_CLI_GFE;
    property RAG_SOC: Nullable<string> read FRAG_SOC write FRAG_SOC;
    property INDIRIZZO: Nullable<string> read FINDIRIZZO write FINDIRIZZO;
    property CITTA: Nullable<string> read FCITTA write FCITTA;
    property PROV: Nullable<string> read FPROV write FPROV;
    property CAP: Nullable<string> read FCAP write FCAP;
    property TELEF_1: Nullable<string> read FTELEF_1 write FTELEF_1;
    property TELEF_2: Nullable<string> read FTELEF_2 write FTELEF_2;
    property DEST_DIV: Boolean read FDEST_DIV write FDEST_DIV;
    property RAG_SOC_DIV: Nullable<string> read FRAG_SOC_DIV write FRAG_SOC_DIV;
    property INDIRIZZO_DIV: Nullable<string> read FINDIRIZZO_DIV write FINDIRIZZO_DIV;
    property CITTA_DIV: Nullable<string> read FCITTA_DIV write FCITTA_DIV;
    property PROV_DIV: Nullable<string> read FPROV_DIV write FPROV_DIV;
    property CAP_DIV: Nullable<string> read FCAP_DIV write FCAP_DIV;
    property TELEF_1_DIV: Nullable<string> read FTELEF_1_DIV write FTELEF_1_DIV;
    property TELEF_2_DIV: Nullable<string> read FTELEF_2_DIV write FTELEF_2_DIV;
    property PART_IVA: Nullable<string> read FPART_IVA write FPART_IVA;
    property COD_FISC: Nullable<string> read FCOD_FISC write FCOD_FISC;
    property EMAIL: Nullable<string> read FEMAIL write FEMAIL;
    property TOT_ESENTE_IVA: Nullable<Double> read FTOT_ESENTE_IVA write FTOT_ESENTE_IVA;
    property TOT_IMPONIBILE: Nullable<Double> read FTOT_IMPONIBILE write FTOT_IMPONIBILE;
    property TOT_IVA: Nullable<Double> read FTOT_IVA write FTOT_IVA;
    property TOT_OMAGGI: Nullable<Double> read FTOT_OMAGGI write FTOT_OMAGGI;
    property TOT_EXTRA: Nullable<Double> read FTOT_EXTRA write FTOT_EXTRA;
    property TOT_DOC: Nullable<Double> read FTOT_DOC write FTOT_DOC;
    property TOT_RICEVUTO: Nullable<Double> read FTOT_RICEVUTO write FTOT_RICEVUTO;
    property TOT_INCASSATO: Nullable<Double> read FTOT_INCASSATO write FTOT_INCASSATO;
    property TOT_RESTO: Nullable<Double> read FTOT_RESTO write FTOT_RESTO;
    property STATO_DOC: Nullable<Integer> read FSTATO_DOC write FSTATO_DOC;
    property DATA_ORA_ASP: Nullable<TDateTime> read FDATA_ORA_ASP write FDATA_ORA_ASP;
    property NOTE_ASP: Nullable<string> read FNOTE_ASP write FNOTE_ASP;
    property CMD_PK1: Nullable<Integer> read FCMD_PK1 write FCMD_PK1;
    property INIZIO_INS: Nullable<TDateTime> read FINIZIO_INS write FINIZIO_INS;
    property FINE_INS: Nullable<TDateTime> read FFINE_INS write FFINE_INS;
    property INIZIO_ESEC: Nullable<TDateTime> read FINIZIO_ESEC write FINIZIO_ESEC;
    property FINE_ESEC: Nullable<TDateTime> read FFINE_ESEC write FFINE_ESEC;
  end;

  [Entity]
  [Table('ORD_RISTO_R')]
  [Id('FPK_1', TIdGenerator.None)]
  [Id('FPK_2', TIdGenerator.None)]
  TORD_RISTO_R = class
  private
    [Column('PK_2', [TColumnProp.Required])]
    FPK_2: Integer;

    [Column('POS_RIGO', [])]
    FPOS_RIGO: Nullable<Integer>;

    [Column('TIPO_RIGO', [], 3)]
    FTIPO_RIGO: Nullable<string>;

    [Column('ART_PK1', [])]
    FART_PK1: Nullable<Integer>;

    [Column('DATICONT_PK2', [])]
    FDATICONT_PK2: Nullable<Integer>;

    [Column('TIPO_ART', [], 3)]
    FTIPO_ART: Nullable<string>;

    [Column('DESC_ART', [], 100)]
    FDESC_ART: Nullable<string>;

    [Column('DESC_BREVE', [], 100)]
    FDESC_BREVE: Nullable<string>;

    [Column('COD_SET', [], 5)]
    FCOD_SET: Nullable<string>;

    [Column('COD_GRP', [], 10)]
    FCOD_GRP: Nullable<string>;

    [Column('COD_UM', [], 5)]
    FCOD_UM: Nullable<string>;

    [Column('VEND_A_FRAZ', [TColumnProp.Required])]
    FVEND_A_FRAZ: Boolean;

    [Column('PZ_PER_CF', [])]
    FPZ_PER_CF: Nullable<Integer>;

    [Column('QUANTITA', [], 18, 4)]
    FQUANTITA: Nullable<Double>;

    [Column('PREZZO', [], 18, 4)]
    FPREZZO: Nullable<Double>;

    [Column('PREZZO_IVATO', [TColumnProp.Required])]
    FPREZZO_IVATO: Boolean;

    [Column('TOT_IMPORTO', [], 18, 4)]
    FTOT_IMPORTO: Nullable<Double>;

    [Column('TOT_IMP_NET', [], 18, 4)]
    FTOT_IMP_NET: Nullable<Double>;

    [Column('TOT_IVA', [], 18, 4)]
    FTOT_IVA: Nullable<Double>;

    [Column('TOT_RIGO', [], 18, 4)]
    FTOT_RIGO: Nullable<Double>;

    [Column('MEZZA_PORZ', [TColumnProp.Required])]
    FMEZZA_PORZ: Boolean;

    [Column('VALUTA_QTA_VAR', [TColumnProp.Required])]
    FVALUTA_QTA_VAR: Boolean;

    [Column('APPLICA_RID_VAR', [TColumnProp.Required])]
    FAPPLICA_RID_VAR: Boolean;

    [Association([TAssociationProp.Lazy], CascadeTypeAllButRemove - [TCascadeType.Flush])]
    [JoinColumn('PK_1', [TColumnProp.Required])]
    FPK_1: TORD_RISTO_T;

  public
    property PK_2: Integer read FPK_2 write FPK_2;
    property POS_RIGO: Nullable<Integer> read FPOS_RIGO write FPOS_RIGO;
    property TIPO_RIGO: Nullable<string> read FTIPO_RIGO write FTIPO_RIGO;
    property ART_PK1: Nullable<Integer> read FART_PK1 write FART_PK1;
    property DATICONT_PK2: Nullable<Integer> read FDATICONT_PK2 write FDATICONT_PK2;
    property TIPO_ART: Nullable<string> read FTIPO_ART write FTIPO_ART;
    property DESC_ART: Nullable<string> read FDESC_ART write FDESC_ART;
    property DESC_BREVE: Nullable<string> read FDESC_BREVE write FDESC_BREVE;
    property COD_SET: Nullable<string> read FCOD_SET write FCOD_SET;
    property COD_GRP: Nullable<string> read FCOD_GRP write FCOD_GRP;
    property COD_UM: Nullable<string> read FCOD_UM write FCOD_UM;
    property VEND_A_FRAZ: Boolean read FVEND_A_FRAZ write FVEND_A_FRAZ;
    property PZ_PER_CF: Nullable<Integer> read FPZ_PER_CF write FPZ_PER_CF;
    property QUANTITA: Nullable<Double> read FQUANTITA write FQUANTITA;
    property PREZZO: Nullable<Double> read FPREZZO write FPREZZO;
    property PREZZO_IVATO: Boolean read FPREZZO_IVATO write FPREZZO_IVATO;
    property TOT_IMPORTO: Nullable<Double> read FTOT_IMPORTO write FTOT_IMPORTO;
    property TOT_IMP_NET: Nullable<Double> read FTOT_IMP_NET write FTOT_IMP_NET;
    property TOT_IVA: Nullable<Double> read FTOT_IVA write FTOT_IVA;
    property TOT_RIGO: Nullable<Double> read FTOT_RIGO write FTOT_RIGO;
    property MEZZA_PORZ: Boolean read FMEZZA_PORZ write FMEZZA_PORZ;
    property VALUTA_QTA_VAR: Boolean read FVALUTA_QTA_VAR write FVALUTA_QTA_VAR;
    property APPLICA_RID_VAR: Boolean read FAPPLICA_RID_VAR write FAPPLICA_RID_VAR;
  end;

implementation

{ TORD_RISTO_T }

constructor TORD_RISTO_T.Create();
begin
  FORD_RISTO_R.SetInitialValue(TList<TORD_RISTO_R>.Create);
end;
// -------------------------------
function TORD_RISTO_T.Get_ORD_RISTO_R: TList<TORD_RISTO_R>;
begin
  Result:=FORD_RISTO_R.Value;
end;
// -------------------------------
destructor TORD_RISTO_T.Destroy();
begin
  FORD_RISTO_R.DestroyValue();
  inherited;
end;

The error indicates that you are sending an object with id 137, 1 to the server. That record does not exist in database. Thus it cannot merge such object. XData won't try to insert a new record because the object already has an id.

But this error happen when i edit the master even when i close application, try to reload all data and modify only the master with a simple

If Not (wdTOrd.State In [dsEdit,dsInsert])Then
  wdTOrd.Edit();
wdTOrd.FieldByName('Tot_Doc').AsFloat:=TotOrd;
wdTOrd.Post();

is json structure fault ?

Querystring
master : Format('$filter=(PK_1 eq %d)&$expand=ORD_RISTO_R/PK_1',[OrdPK1]);
detail : $expand=PK_1

its correct ?

Thx

I don't know how does it relate? What does the query string of JSON structure has to do with the mentioned error. I explained one reason why the error might be happening, have you investigated that path?