Hello,
I have a dataset (TXDataWebDataset) loading an object with multiple sub objects that I get flawlessly thanks to the sub-props depth setting (myWebDataset.SubpropsDepth := 2).
I get an exception when trying to insert a new entry in the dataset, telling me subprop-fields are unknown.
here is a modified part of my code :
Model
Entity]
[Model('Model1')]
[Table('COMMANDE')]
[Sequence('GN_COMMANDE_ID')]
[Id('FChrono', TIdGenerator.IdentityOrSequence)]
TCommande = class
private
[Column('CHRONO', [TColumnProp.Required])]
FChrono: Integer;
[ManyValuedAssociation([], CascadeTypeAll)] // , 'FCommande')]
[ForeignJoinColumn('ID_ORDER', [TColumnProp.Required])]
FLINES: TList<TLine>;
public
constructor Create;
destructor Destroy; override;
property Chrono: Integer read FChrono write FChrono;
property LINES: TList<TLine> read FLINES write FLINES;
end;
[Entity]
[Model('Model1')]
[Table('LINE')]
[Sequence('GN_LINE_ID')]
[Id('FChrono', TIdGenerator.IdentityOrSequence)]
TLine = class
private
[Column('CHRONO', [TColumnProp.Required])]
FChrono: Integer;
[Column('ID_ORDER', [TColumnProp.Required])]
FCommande: Integer;
//[Association([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan)]
//[JoinColumn('ID_ORDER', [TColumnProp.Required])]
//FCOMMANDE: Proxy<TCommande>;
[Association([], CascadeTypeAllButRemove)]
[JoinColumn('ID_PRODUIT', [])]
FPRODUIT: TProduit;
public
property Chrono: Integer read FChrono write FChrono;
property Commande: Integer read FCommande write FCommande;
property PRODUIT: TProduit read FPRODUIT write FPRODUIT;
end;
[Entity]
[Model('Model1')]
[Table('PRODUIT')]
[Id('FChrono', TIdGenerator.None)]
TProduit = class
private
[Column('CHRONO', [TColumnProp.Required])]
FChrono: Integer;
[Association([TAssociationProp.Lazy])]
[JoinColumn('ID_MASTER', [TColumnProp.NoUpdate])]
FPRODUITMASTER: Proxy<TProduit>;
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllButRemove, 'FProduit')]
[OrderBy('CHRONO')]
FPHOTOS: Proxy<TList<TPhotoProduit>>;
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllButRemove, 'FProduitMaster')]
FPRODUITSCHILDREN: Proxy<TList<TProduit>>;
function getPhotos: TList<TPhotoProduit>;
procedure setPhotos(Value : TList<TPhotoProduit>);
function getProduitMaitre: TProduit;
procedure setProduitMaitre(Value : TProduit);
function getProduitsEnfants: TList<TProduit>;
procedure setProduitsEnfants(Value : TList<TProduit>);
public
constructor Create;
destructor Destroy; override;
property Chrono: Integer read FChrono write FChrono;
property PRODUITMASTER: TProduit read getProduitMaitre write setProduitMaitre;
property PHOTOS: TList<TPhotoProduit> read getPhotos write setPhotos;
property PRODUITSCHILDREN: TList<TProduit> read getProduitsEnfants write setProduitsEnfants;
end;
[Entity]
[Model('Model1')]
[Table('PHOTO_PRODUIT')]
[Id('FChrono', TIdGenerator.None)]
TPhotoProduit = class
private
[Column('CHRONO', [TColumnProp.Required])]
FChrono: Integer;
[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[JoinColumn('ID_ART', [TColumnProp.Required])]
FProduit: Proxy<TProduit>;
function getProduit : TProduit;
procedure setProduit(Value : TProduit);
public
property Chrono: Integer read FChrono write FChrono;
property Produit: TProduit read getProduit write setProduit;
end;
Insertion
WDSetLine.SubpropsDepth := 0;
try
WDSetLine.Insert;
//TJSObject(WDSetLine.CurrentData)['COMMANDE@xdata.ref'] := Format('Commande(%s)', [TJSObject(WDSetMaster.CurrentData)['chrono']]);
//TJSObject(WDSetLine.CurrentData)['COMMANDE'] := JS.new(['chrono', WDSetMaster.FieldByName('Chrono').AsInteger]);
WDSetLine.FieldByName('Commande').AsInteger := WDSetMaster.FieldByName('Chrono').AsInteger;
TJSObject(WDSetLine.CurrentData)['PRODUIT@xdata.ref'] := Format('Produit(%d)', [myProductId]);
WDSetLine.Post;
WDSetLine.ApplyUpdates;
Result := True;
finally
WDSetLignes.SubpropsDepth := 2;
end;
I removed the link-back to the master table (lines in //commentary) to be able to move on, but the link to the product must stay available on the table, as well as the photographs associated to the product. So I tried reducing the SubpropsDepth to 0 with... 0 difference.
on ApplyUpdates when the association to the master table is activated, I get
Property "COMMANDE.LINES" does not refer to a known property in type "XData.Default.Line"
the child refers to the master, that refers to the children... so i commented to only keep the link master-child.
But with current code, I get the exception :
Property "PRODUIT.PRODUITMASTER" does not refer to a known property in type "XData.Default.Line"
So I don't really know how to solve any of the problems here.