Association returns wrong null-value

We have a One-To-Many association. In this example a tree-structure. A entity has an entity of the same class as a parent.


TRechtListe = TList<TRecht>;
[Entity, Automapping]
  [Entity, Automapping]
  [Table('Recht')]
  TRecht = class(TPersistent)
  strict private
    FID: Integer;
    ...
    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('ID_Parent', [], 'ID')]
    FParent: Proxy<TRecht>;
    [ManyValuedAssociation([], [TCascadeType.SaveUpdate, TCascadeType.Remove], 'FParent')]
    FRechtListe: TRechtListe;


And an association to that class


[Entity, Automapping]
  [Table('BenutzerRecht')]
  TBenutzerRecht = class(TObject)
  strict private
    FID: Integer;
    ...
    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('ID_Recht', [], 'ID')]
    FRecht: Proxy<TRecht>;


If we call http://localhost:8080/xdata/Recht all objects are correct (especialy parent-property):


....{
            "$id": 3,
            "@xdata.type": "XData.Default.Recht",
            "ID": 3,
            "Name": "Kunden",
            "Parent@xdata.proxy": "Recht(3)/Parent",
            "RechtGruppe@xdata.ref": "RechtGruppe(1)",
            "RechtListe@xdata.proxy": "Recht(3)/RechtListe"
        },
        {
            "$id": 4,
            "@xdata.type": "XData.Default.Recht",
            "ID": 4,
            "Name": "Stamm",
            "Parent@xdata.proxy": "Recht(4)/Parent",
            "RechtGruppe@xdata.ref": "RechtGruppe(2)",
            "RechtListe": []
        },
....


But if we call http://localhost:8080/xdata/Benutzerrecht?$expand=Recht
some expanded properties shows null for the parent-property


....
 {
            "$id": 5,
            "@xdata.type": "XData.Default.BenutzerRecht",
            "ID": 3,
            "CodeZulassen": 1,
            "CodeVerweigern": 0,
            "Recht": {
                "$id": 6,
                "@xdata.type": "XData.Default.Recht",
                "ID": 3,
                "Name": "Kunden",
                "Parent@xdata.proxy": "Recht(3)/Parent",
                "RechtGruppe@xdata.ref": "RechtGruppe(1)",
                "RechtListe@xdata.proxy": "Recht(3)/RechtListe"
            },
            "Benutzer@xdata.proxy": "BenutzerRecht(3)/Benutzer"
        },
        {
            "$id": 7,
            "@xdata.type": "XData.Default.BenutzerRecht",
            "ID": 4,
            "CodeZulassen": 126,
            "CodeVerweigern": 0,
            "Recht": {
                "$id": 8,
                "@xdata.type": "XData.Default.Recht",
                "ID": 4,
                "Name": "Stamm",
                "Parent": null,
                "RechtGruppe": null,  //<== also wrong !
                "RechtListe": []
            },
            "Benutzer@xdata.proxy": "BenutzerRecht(4)/Benutzer"
        },
....


Could anybody explain this behavior?
thanks


The associated objects are only expanded until a specified level. From a specified depth-level and on, associations will not be retrieved and will come with "null". In a case you have objects in the same level which have the associations and others not, that might happen simply because some of those objects were first retrieved at a higher level, previously in the JSON tree, thus they are already in memory.