Aurelius Service weird reply

Hello,

I have a problem with an object return by a query. The foreign keys are not lazy-loaded, I even tried to force the fetch mode to "Eager", but I get a resulting object that doesn't contain the sub-tables i need.

part of the model

[Entity]
  [Table('CARTE_CLIENT_CATEGORIE')]
  [Sequence('GNNUM_CARTE_CLIENT_CATEGORIE')]
  [Id('FCODECHRONO', TIdGenerator.IdentityOrSequence)]
  TCarteClientCategorie = class
  private
    [Column('CODECHRONO', [TColumnProp.Required])]
    FCODECHRONO: Integer;

    [Column('IDCARTE', [])]
    FIDCARTE: Nullable<Integer>;

    [Column('ORDRE', [])]
    FORDRE: Nullable<Integer>;

    [Column('LIBELLE', [], 40)]
    FLIBELLE: Nullable<string>;

    [Column('IMAGE', [])]
    FIMAGE: Nullable<TBlob>;

    [ManyValuedAssociation([], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FIDCATEGORIE')]
    FCarteClientProduits : TList<TCarteClientProduit>;
  public
    constructor Create;
    destructor Destroy; override;
    property CODECHRONO: Integer read FCODECHRONO write FCODECHRONO;
    property IDCARTE: Nullable<Integer> read FIDCARTE write FIDCARTE;
    property ORDRE: Nullable<Integer> read FORDRE write FORDRE;
    property LIBELLE: Nullable<string> read FLIBELLE write FLIBELLE;
    property IMAGE: Nullable<TBlob> read FIMAGE write FIMAGE;
    property CARTECLIENTPRODUITS: TList<TCarteClientProduit> read FCarteClientProduits;
  end;

  [Entity]
  [Table('CARTE_CLIENT_PRODUITS')]
  [Sequence('GNNUM_CARTE_CLIENT_PRODUITS')]
  [Id('FCODECHRONO', TIdGenerator.IdentityOrSequence)]
  TCarteClientProduit = class
  private
    [Column('CODECHRONO', [TColumnProp.Required])]
    FCODECHRONO: Integer;

    [Association([], CascadeTypeAllButRemove)]
    [JoinColumn('IDCATEGORIE', [], 'CODECHRONO')]
    FIDCATEGORIE: TCarteClientCategorie;

    [Column('IDPRODUIT', [])]
    FIDPRODUIT: Nullable<Integer>;

    [Column('ORDRE', [])]
    FORDRE: Nullable<Integer>;
  public        
    property CODECHRONO: Integer read FCODECHRONO write FCODECHRONO;
    property IDCATEGORIE: TCarteClientCategorie read FIDCATEGORIE write FIDCATEGORIE;
    property IDPRODUIT: Nullable<Integer> read FIDPRODUIT write FIDPRODUIT;
    property ORDRE: Nullable<Integer> read FORDRE write FORDRE;
  end;




The query

function TDemandesClientsService.getCarte(id: Integer): TObjectList<TCarteClientCategorie>;
var
  objectManager : TObjectManager;
begin
  objectManager := TXDataOperationContext.Current.GetManager;
  Result := objectManager.Find<TCarteClientCategorie>
    .Where(Linq[Dic.CarteClientCategorie.IDCARTE.PropName] = id)
    .CreateAlias('CARTECLIENTPRODUITS', 'p', TFetchMode.Eager)
    .AddOrder(TOrder.Asc(Dic.CarteClientCategorie.ORDRE.PropName))
    .AddOrder(TOrder.Asc('p.ORDRE'))
    .List;
end;



The resulting JS object received by Web Core' javascript

Categories: (19) [

  0: {​​
    "$id": 1​​
    "@xdata.type": "XData.Default.CarteClientCategorie"​​
    CODECHRONO: 1​​
    "CarteClientProduits@xdata.proxy": "CarteClientCategorie(1)/CarteClientProduits"​​
    IDCARTE: 1​​
    IMAGE: null​​
    LIBELLE: "Lib1"​​
    ORDRE: 1​​

  }​

  1: {
    "$ref": 1​​

  }​

  2: {
    "$ref": 1​​

  }​

  3: {
    "$ref": 1​​

  }​

  4: {
    "$id": 2​​
    "@xdata.type": "XData.Default.CarteClientCategorie"​​
    CODECHRONO: 2​​

    CarteClientProduits: []​​
    IDCARTE: 1​​
    IMAGE: null​​
    LIBELLE: "Lib2"​​
    ORDRE: 2​​  }

5: {

    "$id": 3

    "@xdata.type": "XData.Default.CarteClientCategorie"

    CODECHRONO: 33

    "CarteClientProduits@xdata.proxy": "CarteClientCategorie(33)/CarteClientProduits"

    IDCARTE: 1

    IMAGE: null

    LIBELLE: "Lib3"

    ORDRE: 3
  }

etc...
]



Those empty nodes correspond to child elements but i don't understand why they are empty, and why they are at the root of the array



  1: {
    "$ref": 1​​

    }​



When there are no child element, I get an empty object, that the only point OK, but when there must be entries I get a proxy link
"CarteClientProduits@xdata.proxy": "CarteClientCategorie(1)/CarteClientProduits"

I may do things wrong somewhere or simply don't understand what I get.
Thanks in advance for your help.

You are using


   .CreateAlias('CARTECLIENTPRODUITS', 'p', TFetchMode.Eager)

Which is more or less the equivalent of a SQL JOIN between categories and products. This mean categories will be repeated for each product they contain. That's why you are getting multiple categories, and the $ref: 1 means that it's the same instance as the previous one, they are all repeated instances.
Thanks !
Now I narrowed this problem to Aurelius and not Web Core, or maybe the interaction of the two.
So I removed this element, but still information from linked tables are not loaded, I still get this proxy thing :

There seams to be a problem in the definition, or some way to force the query to load those data.

Add "$expand=SecondTableList" to the QueryString.

https://download.tmssoftware.com/business/xdata/doc/web/expand.html

So it's not possible with object manager ?

Right, I removed the service and on the client side I replaced RawInvoke with List and $expand and I do get all my data... I would prefer tweaking my query on server side but since I can move on, I'll let it this way for now.

Thanks for your time. If there's a solution to get the query on server side to work as I need, i'm still open to suggestions.

You can use $expand with service operations as well.