diff --git a/CHANGELOG.md b/CHANGELOG.md index 3534804b..c19157ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ CHANGED: REMOVED: +- The deprecated `AbstractRelationship::omitWhenNotIncluded()` method (__BREAKING CHANGE__): use `AbstractRelationship::omitDataWhenNotIncluded()` + FIXED: - Regression with uninitialized Resource properties diff --git a/README.md b/README.md index a9d91bb5..d1d050d3 100644 --- a/README.md +++ b/README.md @@ -891,13 +891,13 @@ 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. @@ -919,7 +919,7 @@ public function getRelationships($user): array }, $this->contactTransformer ) - ->omitWhenNotIncluded() + ->omitDataWhenNotIncluded() ; }, ]; diff --git a/examples/Book/JsonApi/Resource/BookResource.php b/examples/Book/JsonApi/Resource/BookResource.php index 50163a1b..7f3885c0 100644 --- a/examples/Book/JsonApi/Resource/BookResource.php +++ b/examples/Book/JsonApi/Resource/BookResource.php @@ -159,7 +159,7 @@ public function getRelationships($book): array ->setSelf(new Link("/relationships/publisher")) ) ->setData($book["publisher"], $this->publisherTransformer) - ->omitWhenNotIncluded() + ->omitDataWhenNotIncluded() ; } ]; diff --git a/examples/User/JsonApi/Resource/UserResource.php b/examples/User/JsonApi/Resource/UserResource.php index c8cdfe5b..ad2674ee 100644 --- a/examples/User/JsonApi/Resource/UserResource.php +++ b/examples/User/JsonApi/Resource/UserResource.php @@ -128,7 +128,7 @@ public function getRelationships($user): array ->setDataAsCallable(function () use ($user) { return $user["contacts"]; }, $this->contactTransformer) - ->omitWhenNotIncluded() + ->omitDataWhenNotIncluded() ; } ]; diff --git a/src/JsonApi/Schema/Relationship/AbstractRelationship.php b/src/JsonApi/Schema/Relationship/AbstractRelationship.php index 05ebe98e..c441e2a5 100644 --- a/src/JsonApi/Schema/Relationship/AbstractRelationship.php +++ b/src/JsonApi/Schema/Relationship/AbstractRelationship.php @@ -143,7 +143,7 @@ public function setDataAsCallable(callable $callableData, ResourceInterface $res /** * @return $this */ - public function omitWhenNotIncluded() + public function omitDataWhenNotIncluded() { $this->omitDataWhenNotIncluded = true; diff --git a/tests/JsonApi/Double/FakeRelationship.php b/tests/JsonApi/Double/FakeRelationship.php index 7ce78228..9297a822 100644 --- a/tests/JsonApi/Double/FakeRelationship.php +++ b/tests/JsonApi/Double/FakeRelationship.php @@ -27,7 +27,7 @@ public function getRelationshipData() return $this->getData(); } - public function isOmitWhenNotIncluded(): bool + public function isOmitDataWhenNotIncluded(): bool { return $this->omitDataWhenNotIncluded; } diff --git a/tests/JsonApi/Schema/Relationship/AbstractRelationshipTest.php b/tests/JsonApi/Schema/Relationship/AbstractRelationshipTest.php index ef19cec9..69c02102 100644 --- a/tests/JsonApi/Schema/Relationship/AbstractRelationshipTest.php +++ b/tests/JsonApi/Schema/Relationship/AbstractRelationshipTest.php @@ -99,13 +99,13 @@ function () { /** * @test */ - public function dataNotOmittedWhenNotIncludedByDefault() + public function dataNotOmittedByDefault() { $relationship = $this->createRelationship(); - $omit = $relationship->isOmitWhenNotIncluded(); + $isDataOmittedWhenNotIncluded = $relationship->isOmitDataWhenNotIncluded(); - $this->assertFalse($omit); + $this->assertFalse($isDataOmittedWhenNotIncluded); } /** @@ -115,10 +115,9 @@ public function omitDataWhenNotIncluded() { $relationship = $this->createRelationship(); - $relationship->omitWhenNotIncluded(); - $omit = $relationship->isOmitWhenNotIncluded(); + $relationship->omitDataWhenNotIncluded(); - $this->assertTrue($omit); + $this->assertTrue($relationship->isOmitDataWhenNotIncluded()); } /** @@ -252,7 +251,7 @@ public function transformWithEmptyData() public function transformWithEmptyOmittedData() { $relationship = $this->createRelationship() - ->omitWhenNotIncluded(); + ->omitDataWhenNotIncluded(); $relationshipObject = $relationship->transform( new ResourceTransformation(