Skip to content

Commit 8ae0682

Browse files
committed
Prevent error with empty relationships without links
1 parent 0bb094b commit 8ae0682

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Serializer.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ private function addToMap(ResourceType $resource, $model, array $include)
8888
}
8989
}
9090

91-
$data['fields'][$name] = $value;
91+
if (!empty($value)) {
92+
$data['fields'][$name] = $value;
93+
}
9294
}
9395

9496
$data['links']['self'] = new SelfLink($resourceUrl);
@@ -175,11 +177,17 @@ private function toMany(Schema\HasMany $field, $model, AdapterInterface $adapter
175177
);
176178
}
177179

178-
private function emptyRelationship(Relationship $field, string $resourceUrl): EmptyRelationship
180+
private function emptyRelationship(Relationship $field, string $resourceUrl): ?EmptyRelationship
179181
{
182+
$links = $this->getRelationshipLinks($field, $resourceUrl);
183+
184+
if (! $links) {
185+
return null;
186+
}
187+
180188
return new EmptyRelationship(
181189
$field->getName(),
182-
...$this->getRelationshipLinks($field, $resourceUrl)
190+
...$links
183191
);
184192
}
185193

0 commit comments

Comments
 (0)