Prevent error with empty relationships without links

This commit is contained in:
Toby Zerner 2019-10-03 16:19:56 +09:30
parent 0bb094ba29
commit 8ae0682d3a
1 changed files with 11 additions and 3 deletions

View File

@ -88,7 +88,9 @@ final class Serializer
}
}
$data['fields'][$name] = $value;
if (!empty($value)) {
$data['fields'][$name] = $value;
}
}
$data['links']['self'] = new SelfLink($resourceUrl);
@ -175,11 +177,17 @@ final class Serializer
);
}
private function emptyRelationship(Relationship $field, string $resourceUrl): EmptyRelationship
private function emptyRelationship(Relationship $field, string $resourceUrl): ?EmptyRelationship
{
$links = $this->getRelationshipLinks($field, $resourceUrl);
if (! $links) {
return null;
}
return new EmptyRelationship(
$field->getName(),
...$this->getRelationshipLinks($field, $resourceUrl)
...$links
);
}