Skip to Content
Feb 02, 2021 at 01:59 PM

ODataModel v2: modify navigation property

42 Views Last edit Feb 03, 2021 at 07:29 AM 2 rev

Hi experts,

a question that I have seen pop up a couple of times, but I couldn't find a satisfying solution.

I have 2 entity types:

  • Contract with key property Id
  • Project with key property ProjId2

and I have the following entities:

ContractSet('A'): { 
Id: "A", 
ProjId: "X"
ProjId2: "X",                              
SomeProp: "1" }
ProjId2: "Y",                             
SomeProp: "2"               

There is an (1:1) association between the two entitypes: Contract.ProjId = Project.ProjId2, with on both sides a navigation property (Project, resp. Contract)

I want to select a different project for the contract (in the frontend, without updating the data in the backend).

I now execute:

let sProjId = oModel.getProperty("/ProjectSet('X')/ProjId2");

the value of sProjId is now "Y".

In my oModel.oData, I now see 2 instances with the same ProjId2 value.

So /ContractSet('A')/Project still refers to the same Project X. It has simply updated the ProjId property as well as the ProjId2 property of the referred Project. How can I correctly update the /ConstractSet('A')/Project reference to point to the newly selected project Y? (without updating the data in the backend).