Support for collections of navigational properties
When generating the bundle to be sent to the server on saving of entities I suggest we use this method, I've been using it in the past and haven't seen any issues (yet)
function unwrapInstance(structObj, transformFn) {
if (!structObj.unwrapped) {
structObj.unwrapped = true;
var rawObject = {};
var stype = structObj.entityType || structObj.complexType;
var serializerFn = getSerializerFn(stype);
var unmapped = {};
stype.dataProperties.forEach(function (dp) {
if (dp.isComplexProperty) {
rawObject[dp.nameOnServer] = _map(structObj.getProperty(dp.name), function (co) {
if (!co.unwrapped) {
return unwrapInstance(co, transformFn);
}
});
} else {
var val = structObj.getProperty(dp.name);
val = transformFn ? transformFn(dp, val) : val;
if (val === undefined) return;
val = serializerFn ? serializerFn(dp, val) : val;
if (val !== undefined) {
if (dp.isUnmapped) {
unmapped[dp.nameOnServer] = _toJSONSafe(val);
} else {
rawObject[dp.nameOnServer] = val;
}
}
}
});
stype.navigationProperties.forEach(function (dp) {
rawObject[dp.nameOnServer] = __map(structObj.getProperty(dp.name), function (co) {
if (!co.unwrapped) {
return unwrapInstance(co, transformFn);
}
});
});
if (!__isEmpty(unmapped)) {
rawObject.__unmapped = unmapped;
}
return rawObject;
}
}
It will handle making sure it doesn't infinitely unwrap navigational properties due to the fact those viewmodels need foreign key properties to their inverse parent.
Thanks! Let me know if this has already been done or I'm doing something off the wall

-
kateen commented
please add this