I'm trying to mock some data based on existing and working oData models. The Mock Server works, but I am struggling making the $expand to do it's job. I think it's mostly a matter of me not understanding where or how to store the JSON.
The metadata file is copied verbatim from the working service and contains all entities, entitysets, associations etcetera.
Here are some of the relevant bits. From Users entity:
<NavigationProperty Name="Dealers" Relationship="Y_DP_CORE_SRV.User_Dealer" FromRole="FromRole_User_Dealer" ToRole="ToRole_User_Dealer" />
The association:
<Association Name="User_Dealer" sap:content-version="1">
<End Type="Y_DP_CORE_SRV.User" Multiplicity="1" Role="FromRole_User_Dealer" />
<End Type="Y_DP_CORE_SRV.Dealer" Multiplicity="*" Role="ToRole_User_Dealer" />
<ReferentialConstraint>
<Principal Role="FromRole_User_Dealer">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="ToRole_User_Dealer">
<PropertyRef Name="Id" />
</Dependent>
</ReferentialConstraint>
</Association>
I can get Users('PRX-00015'). I cannot get Users('PRX-00015')/Dealers or Users('PRX-00015')?$expand=Dealers. There are no errors, but also no data.
Here's Users.JSON:
[{
"__metadata": {
"id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')",
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')",
"type": "Y_DP_CORE_SRV.User"
},
"Id": "PRX-00015",
"FullName": "Jorg",
"Email": "",
"Telephone": "",
"InternalUser": false,
"Enabled": true,
"Dealers": {
"results": [{
"__metadata": {
"id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
"type": "Y_DP_CORE_SRV.Dealer"
},
"Id": "AA2002"
}, {
"__metadata": {
"id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
"type": "Y_DP_CORE_SRV.Dealer"
},
"Id": "AA1046"
}]
},
}]
I can also use the unexpanded version of Dealers and move the array into a Dealers.json file of it's own, in which case the line looks like
"Dealers": {
"__deferred": {
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')/Dealers"
}
}
And Dealers.json
[{
"__metadata": {
"id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
"type": "Y_DP_CORE_SRV.Dealer"
},
"Id": "AA2002"
}, {
"__metadata": {
"id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
"uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
"type": "Y_DP_CORE_SRV.Dealer"
},
"Id": "AA1046"
}]
All of these result in an empty Dealers array (Dealers.length being 0). Anyone know how this works?