Skip to Content
0
Former Member
Oct 08, 2019 at 04:00 PM

UI5 - Mockserver - JSON Relationship

286 Views Last edit Oct 11, 2019 at 09:48 AM 8 rev

Hello,

I need help to setup Relationships between Entitys on a mockup server. With my ODATA Service (v2.0 Olingo) the application works well.

I have already tried the following patterns, but it does not work. I got with all my solution a reference to "DocumenTypes T1".

"uri": "/odatademo/xxxxxx.svc/DocumentTypes('T2')" 
"uri": "DocumentTypes ('T2')"

Document.JSON
{
	"Id": 1,
	"Subject": "TEST",
	"DocumentTypeDetails": {
		"Id": "T2",
		"Name": "DEF"
	}
}

Furthermore I tried to follow the FAQ without success.

"Mock data in JSON format can be generated from an OData service by adding the $format=json"

https://sapui5.hana.ondemand.com/1.32.4/docs/guide/c9a91ddaef47461c9c44bfc2198ea3f0.html

{
	"__metadata": {
	  "id": "https://odataXXX.hana.ondemand.com:443/odata/XXX.svc/Documents(1L)",
	  "uri": "https://odataXXX.hana.ondemand.com:443/odata/XXX.svc/Documents(1L)",
	  "type": "XXX.Document"
	},
	"Subject": "Test",
	"DocumentTypeDetails": {
	  "__deferred": {
		"uri": "https://odataXXX.hana.ondemand.com:443/odata/XXX.svc/Documents(1L)/DocumentTypeDetails"
	  }
	}
}

A part of my Code:

localService/mockdata/Documents.JSON

[{
	"Id": 1,
	"Subject": "TEST",
	"DocumentTypeDetails": {
		"__deferred": {
			"uri": "/odata/xxxxxx.svc/DocumentTypes('T2')"
		}
	}
}]<br>

localService/mockdata/DocumentTypes.JSON

[{
	"Id": "T1",
	"Name": "ABC"
},
{
	"Id": "T2",
	"Name": "DEF"
}]

localService/metadata.xml (C&P from OData $metadata)

<EntityType Name="DocumentType">
	<Key>
		<PropertyRef Name="Id"/>
	</Key>
	<Property Name="Id" Type="Edm.String" Nullable="false"/>
	<Property Name="Name" Type="Edm.String" Nullable="true" MaxLength="255"/>
</EntityType>


<EntityType Name="Document">
	<Key>
		<PropertyRef Name="Id"/>
	</Key>
	<Property Name="Id" Type="Edm.Int64" Nullable="false"/>
	<Property Name="Subject" Type="Edm.String" Nullable="true" MaxLength="255"/>
	<NavigationProperty Name="DocumentTypeDetails" Relationship="XXX.Document_DocumentType_Many_ZeroToOne0" FromRole="Document"
		ToRole="DocumentType"/>
</EntityType>


<Association Name="Document_DocumentType_Many_ZeroToOne0">
	<End Type="XXX.Document" Multiplicity="*" Role="Document"/>
	<End Type="XXX.DocumentType" Multiplicity="0..1" Role="DocumentType"/>
</Association>
			
<EntitySet Name="Documents" EntityType="XXX.Document"/>
<EntitySet Name="DocumentTypes" EntityType="XXX.DocumentType"/>


<AssociationSet Name="Document_DocumentType_Many_ZeroToOne0Set" Association="XXX.Document_DocumentType_Many_ZeroToOne0">
	<End EntitySet="Documents" Role="Document"/>
	<End EntitySet="DocumentTypes" Role="DocumentType"/>
</AssociationSet

XML View (short version)

<Table items="{path : 'MyODATA>/Documents', expand : 'DocumentTypeDetails'}">
....
<Texttext="{MyODATA>Subject}"/>
<Texttext="{MyODATA>DocumentTypeDetails/Name}"/>
....

</Table>

Thanks for your Help!