I've been working on integrating the BreezeJS library with an SAP OData service. I have successfully managed to read entities, but I'm facing issues when trying to resolve linked objects.
The EntityType I am dealing with is OrgObject.
<EntityType Name="OrgObject" sap:content-version="1">
<!-- ... -->
<NavigationProperty Name="Children" Relationship="ZGW_ORGSTRUCTURE.OrgObject_To_Children" FromRole="FromRole_OrgObject_To_Children" ToRole="ToRole_OrgObject_To_Children"/>
</EntityType>
There is a link available to resolve all linked OrgObjects (named Children).
<Association Name="OrgObject_To_Children" sap:content-version="1">
<End Type="ZGW_ORGSTRUCTURE.OrgObject" Multiplicity="1" Role="FromRole_OrgObject_To_Children"/>
<End Type="ZGW_ORGSTRUCTURE.OrgObject" Multiplicity="*" Role="ToRole_OrgObject_To_Children"/>
</Association>
Despite this, the breeze query works:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
});
}).fail(/*...*/);
But how can I access the 'children' from this object?
Attempt 1:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
var Children = item.Children();
// ...
});
}).fail(/*...*/);
This attempt leads to an error:
message: "Object [object Object] has no method 'children'"
Attempt 2:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
item.entityAspect.loadNavigationProperty("Children").then(function(data) {
console.log(data.results);
data.results.forEach(function(item) {
console.log(item);
});
}).fail(function(e) {
console.log(e);
});
// ...
});
}).fail(/*...*/);
This approach results in another error:
The 'propertyOrExpr' parameter must be a 'string'
Attempt 3:
var query = new breeze.EntityQuery().from("OrgObjects").expand("Children");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
console.log(item.Children);
console.log( item.Children.length );
// ...
});
}).fail(/*...*/);
Result: item.Children
is an object. However, item.Children.length = 0
.
Although the children are fetched from the server according to the http response, they are not available in the item.Children
object.
Console output:
Finance Department
[parentEntity: Object, navigationProperty: ctor, arrayChanged: ctor, _addsInProcess: Array[0], push: function…]
_addsInProcess: Array[0]
_getEventParent: function () {
_getPendingPubs: function () {
arrayChanged: ctor
length: 0
load: function (callback, errorCallback) {
navigationProperty: ctor
parentEntity: Object
pop: function () {
push: function () {
shift: function () {
splice: function () {
unshift: function () {
__proto__: Array[0]
0
Could someone provide assistance? Is there something lacking in my OData service configuration?