I am receiving some complex types from the server that I want to convert into an array of complex types. There is no foreignKey that is returned from the server to map the complexType back to the parent entity, and due to the high volume of data that can be returned I don't want to create a jsonResultsAdapter to map properties, as it adds additional processing time.
I may not be doing this correctly, but I am adding the complexType this way -
metadataStore.addEntityType({
shortName: "Parent",
namespace: "MyNameSpace",
dataProperties: {
id: { dataType: "Int64", isPartOfKey: true },
name: { dataType: "String" },
complexChildren: { complexTypeName: "ComplexChild:#MyNameSpace", isScalar: false }
}
});
metadataStore.addEntityType({
shortName: "ComplexChild",
namespace: "MyNameSpace",
isComplexType: true,
dataProperties: {
notAForeignKeyId: { dataType: "Int64" },
name: { dataType: "String" }
}
});
This works great, I can see the objects in the object graph, I see that everything is mapped when they are returned from the server, but when I try to treat it as a simple observableArray it is throwing errors -
ko.utils.arrayForEach(parents(), function (parent) {
ko.utils.arrayForEach(parent.complexChildren(), function (child) {
if (child === aComplexIdiot) { }
});
});
Throws an error on line 101 of knockout2.3.0.debug.js. I don't think this is a Breeze issue because everything is being handled properly, so I think it is how I am mapping the complexType's, it just doesn't make a ton of sense why it is happening and I don't want to start creating work arounds unless I have to.
The short-term fix here is to treat the array as a simple JavaScript array instead of a Knockout observable array. So in place of -
ko.utils.arrayForEach(parents(), function (parent) {
ko.utils.arrayForEach(parent.complexChildren(), function (child) {
if (child === aComplexIdiot) { }
});
});
I am using
ko.utils.arrayForEach(parents(), function (parent) {
$.each(parent.complexChildren, function (index, item) {
if (item === aComplexIdiot) { }
});
});
Until the issue is resolved