Skip to content

Commit

Permalink
Deprecated omitWhenNotIncluded
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Apr 5, 2019
1 parent 0a3fc18 commit 05427ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ FIXED:

## 3.1.1 - 2019-04-05

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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,14 +837,14 @@ public function getRelationships($user): array
return
ToManyRelationship::create()
->setData($user["contacts"], $this->contactTransformer)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
}
```

With usage of the `omitWhenNotIncluded()` method, the relationship data will be omitted when the relationship is not
By using the `omitDataWhenNotIncluded()` method, the relationship data will be omitted when the relationship is not
included. However, sometimes this optimization is not enough on its own. Even though we can save bandwidth with the prior
technique, the relationship still has to be loaded from the data source (probably from a database), because we pass it
to the relationship object with the `setData()` method.
Expand All @@ -866,7 +866,7 @@ public function getRelationships($user): array
},
$this->contactTransformer
)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
Expand Down
2 changes: 1 addition & 1 deletion examples/Book/JsonApi/Resource/BookResourceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getRelationships($book): array
)
)
->setData($book["publisher"], $this->publisherTransformer)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
Expand Down
2 changes: 1 addition & 1 deletion examples/User/JsonApi/Resource/UserResourceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function getRelationships($user): array
->setDataAsCallable(function () use ($user) {
return $user["contacts"];
}, $this->contactTransformer)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
Expand Down
9 changes: 9 additions & 0 deletions src/JsonApi/Schema/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public function setDataAsCallable(callable $data, ResourceInterface $resourceTra
/**
* @return $this
*/
public function omitDataWhenNotIncluded()
{
return $this->omitWhenNotIncluded();
}

/**
* @deprecated since 3.1.1, will be removed in 4.0.0. Use omitDataWhenNotIncluded() instead.
* @return $this
*/
public function omitWhenNotIncluded()
{
$this->omitDataWhenNotIncluded = true;
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonApi/Double/FakeRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getRetrieveData()
return $this->retrieveData();
}

public function isOmitWhenNotIncluded(): bool
public function isOmitDataWhenNotIncluded(): bool
{
return $this->omitDataWhenNotIncluded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function dataNotOmittedWhenNotIncludedByDefault()
{
$relationship = $this->createRelationship();

$this->assertFalse($relationship->isOmitWhenNotIncluded());
$this->assertFalse($relationship->isOmitDataWhenNotIncluded());
}

/**
Expand All @@ -63,8 +63,8 @@ public function omitDataWhenNotIncluded()
{
$relationship = $this->createRelationship();

$relationship->omitWhenNotIncluded();
$this->assertTrue($relationship->isOmitWhenNotIncluded());
$relationship->omitDataWhenNotIncluded();
$this->assertTrue($relationship->isOmitDataWhenNotIncluded());
}

/**
Expand Down

0 comments on commit 05427ab

Please sign in to comment.