Skip to content

Commit

Permalink
Relationships with empty data, issue woohoolabs#20
Browse files Browse the repository at this point in the history
* When `transformData` returns an empty data-set (null or and empty array) include this in the response.
* The empty data for a ToManyRelationship is [] not null.
  • Loading branch information
Emil Andersson committed Apr 28, 2016
1 parent 06c3b5e commit a6cb118
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/JsonApi/Schema/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function transform(
) {
$transformedData = $this->transformData($transformation, $relationshipName, $defaultRelationships);
} else {
$transformedData = null;
$transformedData = false;
}

if ($transformation->request->isIncludedField($resourceType, $relationshipName)) {
Expand All @@ -143,7 +143,7 @@ public function transform(
}

// DATA
if (isset($transformedData) === true) {
if ($transformedData !== false) {
$relationship["data"] = $transformedData;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApi/Schema/Relationship/ToManyRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function transformData(
) {
$data = $this->retrieveData();
if (empty($data) || $this->resourceTransformer === null) {
return null;
return [];
}

$content = [];
Expand Down

0 comments on commit a6cb118

Please sign in to comment.