oasis-tcs / odata-specs

OASIS OData TC: Markdown sources for OData specification drafts. https://github.com/oasis-tcs/odata-specs
https://oasis-tcs.github.io/odata-specs/
Other
5 stars 2 forks source link

Should updates of related resources be supported in Create? #352

Open ralfhandl opened 4 months ago

ralfhandl commented 4 months ago

As described in ODATA-1450, when we create a resource we can link it to other, existing resources using @odata.id. We can also create new related resources.

This is similar to what we do with a delta patch operation and, indeed, within a delta patch operation we can create a new entity and create/update/remove related nested entities.

Should we support the same functionality when creating a single resource (i.e., using POST) that we do in a delta update?

Specifically, when we create an item using POST, should we 1) Support referencing existing items by key properties as an alternative to @odata.id? Note that, for non-contained nested resources with no navigation property binding you would have to either include the @odata.context in addition to key values or include the @odata.id. 2) Support modifying properties of related existing items?

Same question for using PUT/PATCH as an upsert – seems like at least PATCH, which already supports keyvalues and nested deltas for update, should also support the same changes as part of a create.

Imported from ODATA-1535

ralfhandl commented 1 month ago

Proposal:

mikepizzo commented 1 month ago

Proposal:

  • Support 1.
  • Do not support 2.

Agree we should support 1.

If we don't support 2, then there will be a difference in behavior between a create request for a single entity versus a create request for a single entity within a bulk operation.

This becomes problematic for upsert requests, since the request is interpreted as an update if the item already exists (and thus, updating related entities is supported) and is interpreted as a create if the item doesn't already exist (in which case, do we error if the payload contained an update to a related entity, where we would have succeeded with the same payload if the entity already existed?).

I propose we split the issues -- use this issue (renamed) to track the use of key values in place of @ids, and create a new issue to propose supporting updating properties of related entities in create.

ralfhandl commented 1 month ago

When trying to split this issue I realized that the underlying question to both parts is

Ideally the answer contains "identical for insert and update".

Splitting this up into sub-questions:

  1. Which effects do we allow?
  2. Which nested entity representations do we allow?
  3. Which nested entity representation has which effect?

Effects

Nested entity representations

{ 
  "@id": 42
}
{ 
  "KeyProp": 42
}
{ 
  "KeyProp": 42,
  "NonKeyOne": "valueOne",
}
{ 
  "NonKeyOne": "valueOne",
}
{ 
  "@id": 42,
  "NonKeyOne": "valueOne",
}

More representations? Feel free to add them here.

ralfhandl commented 1 month ago

In the above framework: