Skip to content

Commit

Permalink
Revert "Fix output for ToOneRelationship when the relationship doesn'…
Browse files Browse the repository at this point in the history
…t contain any keys"
  • Loading branch information
kocsismate committed Apr 18, 2019
1 parent 05427ab commit 18fd37a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
6 changes: 1 addition & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ REMOVED:

FIXED:

## 3.1.1 - 2019-04-05
## 3.1.1 - 2019-04-18

DEPRECATED:

- `ToOneRelationship::omitWhenNotIncluded()`: Use `ToOneRelationship::omitDataWhenNotIncluded()`
- `ToManyRelationship::omitWhenNotIncluded()`: Use `ToManyRelationship::omitDataWhenNotIncluded()`

FIXED:

- [#82](https://github.com/woohoolabs/yin/pull/82): Fix output for ToOneRelationship when the relationship doesn't contain any keys

## 3.1.0 - 2019-01-17

This is a release with several deprecations in order to ensure forward compatibility with Yin 4.0.
Expand Down
8 changes: 4 additions & 4 deletions src/JsonApi/Schema/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ public function transform(
array $defaultRelationships,
array $additionalMeta = []
): ?array {
$relationship = [
"data" => null,
];
$relationship = null;

if ((
$transformation->fetchedRelationship === $relationshipName &&
$this->data !== null &&
$this->data &&
$this->omitDataWhenNotIncluded === false
) ||
$transformation->request->isIncludedRelationship(
Expand All @@ -161,6 +159,8 @@ public function transform(
}

if ($transformation->request->isIncludedField($resourceType, $relationshipName)) {
$relationship = [];

// Links
if ($this->links !== null) {
$relationship["links"] = $this->links->transform();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ public function transformEmpty()
[],
[]
);
$this->assertEquals(
[
"data" => null,
],
$result
);

$this->assertEquals([], $result);
}

private function createRelationship(): FakeRelationship
Expand Down
8 changes: 3 additions & 5 deletions tests/JsonApi/Transformer/AbstractResourceTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ public function transformToManyEmptyRelationship()
$defaultRelationships = ["father"];
$relationships = [
"father" => function () {
$relationship = new ToManyRelationship();
return $relationship;
return new ToManyRelationship();
}
];

Expand All @@ -308,9 +307,8 @@ public function transformToManyEmptyRelationship()
$transformer = $this->createTransformer("user", "1", [], null, [], $defaultRelationships, $relationships);
$transformation = new Transformation($request, $data, new DefaultExceptionFactory(), "");
$transformedResource = $transformer->transformRelationship("father", $transformation, []);
$this->assertEquals([
"data" => [],
], $transformedResource);

$this->assertEquals([], $transformedResource);
}

/**
Expand Down

0 comments on commit 18fd37a

Please sign in to comment.