yin
yin copied to clipboard
Hydrating same type (child, parent) related entity
Hi all,
I need help with this one.
When I have json:api
response data with relationship of same type (e.g. parent or child - relationship with it-self) and their id's are the same, Hydrator
is not capable creating those relationships.
Response example:
Page with id:15 has parent with id:14, but its not present in included
because it already exists in data
array.
"data": [
{
"type": "page",
"id": "15",
"attributes": {
"internal_name": "Company",
"active": 1,
"parent_id": 14
},
"relationships": {
"parent": {
"data": {
"type": "page",
"id": "14"
}
}
}
},
{
"type": "page",
"id": "14",
"attributes": {
"internal_name": "About us",
"parent_id": null
},
"relationships": {
"parent": {
"data": null
}
}
},
{
"type": "page",
"id": "13",
"attributes": {
"internal_name": "Information",
"parent_id": 1
},
"relationships": {
"parent": {
"data": {
"type": "page",
"id": "1"
}
}
}
}
],
"included": [
{
"type": "page",
"id": "1",
"attributes": {
"internal_name": "General",
"parent_id": null
}
}
]
}
Hi @Vivenco,
This is the intended behaviour. The authors of the JSON:API standard wrote somewhere that the response is basically an identity map where none of the items (regardless if they are in the primary data or included) doesn't appear more than once.
Does this answer solve your problem?
@Vivenco I've just realized that you are talking about the Hydrator
(and not about transformers)! Sorry for confusion, I'll have a look at the issue as soon as I have some spare time.