openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

ODataModel v2 should have a setting to not delete navigation properties in change request

Open ManuelB opened this issue 6 years ago • 2 comments

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

ManuelB avatar Mar 16 '18 10:03 ManuelB

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

Shtilianova avatar Mar 23 '18 14:03 Shtilianova

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 15 '19 06:08 CLAassistant

Hi @ManuelB ,

please have a look at https://github.com/SAP/openui5/commit/d75745de6a5fd3d44977a0692b7a0bde5d1bbdf1. Does this solve your pull request?

Best regards Mathias.

uhlmannm avatar Oct 21 '22 13:10 uhlmannm

As described by @uhlmannm this enhancement was implemented. Therefore closing this PR. Thanks a lot for bringing up this topic.

flovogt avatar Dec 12 '22 11:12 flovogt

@flovogt thanks a lot!

ManuelB avatar Dec 12 '22 11:12 ManuelB