on 03-10-2022 12:34 PM
Does CAP / CDS allow us to expose 1 to 1 nested JSON objects? I see that defining a to many relationship creates an object array however, I am trying to expose nested objects without created 1 to n relationship.
To many scenerio:
To one scenerio causes for the entire entity to flatten on itself. I need to be able to control how whether included structures are flattened or nested.
desired structure:
{
"ShipRequest": {
"Pickup":{
"Carrier":"string",
...
}
}
}<br>
After some trial and error, I found a solution for my use case shown below. I'm very interested if there are other suggetions on how to accomplish this without declaring types as entities.
cds definition:
swagger-ui
metadata:
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<script/>
<edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ShipExecService">
<EntityContainer Name="EntityContainer">
<EntitySet Name="Shipments" EntityType="ShipExecService.Shipments">
<NavigationPropertyBinding Path="type" Target="type1"/>
</EntitySet>
<EntitySet Name="type1" EntityType="ShipExecService.type1"/>
</EntityContainer>
<EntityType Name="Shipments">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<NavigationProperty Name="type" Type="ShipExecService.type1">
<OnDelete Action="Cascade"/>
</NavigationProperty>
</EntityType>
<EntityType Name="type1">
<Property Name="field1" Type="Edm.String"/>
<Property Name="field2" Type="Edm.String"/>
</EntityType>
<Annotations Target="ShipExecService.Shipments/ID">
<Annotation Term="Core.Computed" Bool="true"/>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
11 | |
10 | |
8 | |
8 | |
6 | |
6 | |
6 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.