openui5
openui5 copied to clipboard
ODataModel v2 should have a setting to not delete navigation properties in change request
Hello, I need a possibility to tell the ODataModel that is should keep my navigation properties. Currently I am replacing the _processChange function with my own version and:
/* sap.ui.define(["sap/ui/model/odata/v2/ODataModel"], function(ODataModel) { ... */
// Do not delete navigation properties
oDataModel._processChange = function (sKey, oData, sUpdateMethod) {
// recover navigation properties
var oEntityType = this.oMetadata._getEntityTypeByPath(sKey);
var aNavProps = this.oMetadata._getNavigationPropertyNames(oEntityType);
var oNavigationProperties = {};
// do a copy of the payload or the changes will be deleted in the model as well (reference)
var oPayload = jQuery.sap.extend(true, {}, this._getObject('/' + sKey, true), oData);
aNavProps.forEach(function(sNavPropName) {
if(oPayload[sNavPropName]) {
oNavigationProperties[sNavPropName] = oPayload[sNavPropName];
}
});
var oRequest = ODataModel.prototype._processChange.apply(this, arguments);
for(var sNavigationProperty in oNavigationProperties) {
if("__deferred" in oNavigationProperties[sNavigationProperty] &&
"uri" in oNavigationProperties[sNavigationProperty].__deferred) {
var sUri = oNavigationProperties[sNavigationProperty].__deferred.uri;
if(!sUri.match(/^https?:\/\//)) {
oRequest.data[sNavigationProperty] = oNavigationProperties[sNavigationProperty];
}
}
}
return oRequest;
};
/* ... */
It would be awesome if a property is available to turn off the deletion of navigation propertis.
/Manuel
Hello @ManuelB , Thank you for your pull request. I've created an internal record 1870087720. The status of the issue will be updated here in GitHub. Regards, Diana
Hi @ManuelB ,
please have a look at https://github.com/SAP/openui5/commit/d75745de6a5fd3d44977a0692b7a0bde5d1bbdf1. Does this solve your pull request?
Best regards Mathias.
As described by @uhlmannm this enhancement was implemented. Therefore closing this PR. Thanks a lot for bringing up this topic.
@flovogt thanks a lot!