-
Notifications
You must be signed in to change notification settings - Fork 66
Closed
Description
I have a resource that has many child resources of the same type (e.g. category that has many subcategories), to prevent recursion-related problems (we provide both parent
and children
relationships) I pass only subcategories IDs and not the whole resource object in Schema
's getRelationships()
.
I've tried to use array of Identifier
s, but got error
No Schema found for resource `Neomerx\\JsonApi\\Schema\\Identifier`
which is frustrating. Now I create semi-fake resource objects, that contain only IDs to get identifier objects in json:
if (count($resource->getChildren())) {
$childResources = [];
foreach ($resource->getChildren() as $childId) {
// create fake resource to provide ID
$childResources[] = new Category(['id' => $childId]);
}
$result['children'] = [
self::RELATIONSHIP_DATA => $childResources,
self::RELATIONSHIP_LINKS_SELF => false,
];
}
return $result;
Is this the desired way?