Skip to content

Commit 88c084b

Browse files
authored
Mention that ER references are to-one cardinality only (#101)
* Mention that ER references are to-one cardinality only Signed-off-by: Simon Heimler <simon.heimler@sap.com> * Fix links --------- Signed-off-by: Simon Heimler <simon.heimler@sap.com>
1 parent 904824c commit 88c084b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

docs/primer.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,16 @@ Note: As a general convention we recommend to omit optional boolean properties,
264264

265265
### Cardinality
266266

267-
Please note that CSN Interop does not support arrays of scalar types and arrays of arrays.
268-
There is [cds.Association](./spec-v1/csn-interop-effective#association-type) (array of pointers) and [cds.Composition](./spec-v1/csn-interop-effective#composition-type) (array of entities), which can express "to many" relationship via the [cardinality](./spec-v1/csn-interop-effective#cardinality-object) object.
267+
CSN Interop does not support arrays of scalar types and arrays of arrays.
269268

270-
The reason for not supporting arrays of scalar types is that this is not supported in all tech-stacks and would require a more complex mapping.
269+
There are [cds.Association](./spec-v1/csn-interop-effective#association-type) and [cds.Composition](./spec-v1/csn-interop-effective#composition-type), which can express "to many" relationship via the [cardinality](./spec-v1/csn-interop-effective#cardinality-object) object.
270+
271+
Not supporting arrays of scalar types is a design choice, due to the interoperability quality. Arrays of primitive types are not supported in all tech-stacks (notably relational schemas) and would require a more complex mapping.
271272
By not supporting this in CSN Interop, the model needs to make the decision how multi-value scalar types are to be mapped.
272273

273274
This can be done, e.g. by:
274275

275-
- converting the scalar type to an Entity and use `cds.Association` or `cds.Composition` with the appropriate cardinality (RECOMMENDED).
276+
- converting the scalar type to an Entity and use `cds.Composition` (or `cds.Association`) with the appropriate cardinality (RECOMMENDED).
276277
- converting the array of values into a single string, e.g. by using a delimiter or parsing it to a JSON string.
277278

278279
## Annotations

spec/v1/annotations/entity-relationship.outro.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ The annotation is an array because there could be multiple Entity Types that are
186186
If an array is given, all of the reference targets MUST be valid places where the ID can be resolved, at least in a certain implementation or version of the target entity.
187187
This also allows for references to polymorphic targets that share the same Property Type as an ID (e.g. a reference to either Cat or Dog, sharing the same Pet ID).
188188

189-
> 🚧 Consideration: Provide optional attribute to state that a reference has a "composition" quality, in case that the API Model itself doesn't imply that already.
190-
> This would help to know which entity type instances should be deleted if their parent is deleted and is usually also an indicator for transactional integrity.
189+
**Cardinality**: For references with "to many" cardinality, the property holding the referenced ID must be moved to a separate entity, which is then included as a `cds.Composition` with the desired cardinality. See [cardinality of primitive types](../../primer.md#cardinality).
191190

192191
#### Referencing Composite IDs
193192

@@ -244,6 +243,8 @@ entity PurchaseOrder {
244243
}
245244
```
246245

246+
**Cardinality**: For references with "to many" cardinality, the properties that together form a composite reference must be moved to a separate entity, which is then included as a `cds.Composition` with the desired cardinality. E.g. `mainSupplier: SupplierReference` where the new SupplierReference entity contains the `number` and the `type`. See [cardinality of primitive types](../../primer.md#cardinality).
247+
247248
### Advanced Cases
248249

249250
All the annotations in this section are **optional** for providers and consumers to implement or understand.

0 commit comments

Comments
 (0)