Thanks for response, Thomaxxl!
I don’t understand your example:
{
"data": {
"attributes": {
"name": "Seller 1"
},
"id": "1",
// code before means seller looks like:
// { id: 1, name: 'Seller 1' }
"relationships": {
"appointments": {
"data": [
{
"id": "1",
"type": "Post"
}
],
"links": {
"self": "/Seller/1/appointments"
}
}
},
"type": "Seller"
// code before means seller looks like:
// {
// id: 1,
// name: 'Seller 1',
// appointments: [
// { id: 1 }
// ]
// }
},
"included": [
{
"attributes": {
"date": "0000"
},
"id": "1",
"type": "Post",
"links": { "self": "/Post/1" }
}
]
// code before means seller looks like:
// {
// id: 1,
// name: 'Seller 1',
// appointments: [
// { id: 1, date: '0000' }
// ]
// }
}
Deserialized seller has appointments array, that contains only post and post contains only date. But existing seller has appointments array, that contains post and date, post contains only name.
// deserialized example
{
name: 'Seller 1',
id: '1',
appointments: [
{ date: '0000', id: '1' }
]
}
// original seller
{
name: 'Seller 1',
id: '1',
appointments: [
{ post: { id: 1, name: 'Post 1' }, date: '0000' }
]
}
If I decide to appointment being the resource, json will looks like this:
{
"data": {
"type": "sellers",
"id": "1",
"links": {
"self": "http://localhost/sellers/1"
},
"attributes": {
"name": "seller1"
},
"relationships": {
"appointments": {
"data": [
{
"type": "appointments",
"id": "1"
},
{
"type": "appointments",
"id": "2"
}
]
}
}
},
"included": [
{
"type": "appointments",
"id": "1",
"links": {
"self": "http://localhost/sellers/appointments/1"
},
"attributes": {
"date": "2018-09-09T03:46:26.915Z"
},
"relationships": {
"post": {
"data": {
"type": "posts",
"id": "1"
}
}
}
},
{
"type": "appointments",
"id": "2",
"attributes": {
"date": "2018-09-10T03:46:26.915Z"
},
"links": {
"self": "http://localhost/sellers/appointments/1"
},
"relationships": {
"post": {
"data": {
"type": "posts",
"id": "2"
}
}
}
},
{
"type": "posts",
"id": "1",
"attributes": {
"name": "post1"
},
"links": {
"self": "http://localhost/post/1"
}
},
{
"type": "posts",
"id": "2",
"attributes": {
"name": "post2"
},
"links": {
"self": "http://localhost/post/2"
}
}
]
}
If appointment is not resource means, that it is not contained in “relationships” and “included” props of json. So this is the place where I stuck.