Skip to content

Commit

Permalink
Remove deprecated AbstractRelationship::omitWhenNotIncluded() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Apr 8, 2019
1 parent d4977c5 commit 84f7d0d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGED:

REMOVED:

- The deprecated `AbstractRelationship::omitWhenNotIncluded()` method (__BREAKING CHANGE__): use `AbstractRelationship::omitDataWhenNotIncluded()`

FIXED:

- Regression with uninitialized Resource properties
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -919,7 +919,7 @@ public function getRelationships($user): array
},
$this->contactTransformer
)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
},
];
Expand Down
2 changes: 1 addition & 1 deletion examples/Book/JsonApi/Resource/BookResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function getRelationships($book): array
->setSelf(new Link("/relationships/publisher"))
)
->setData($book["publisher"], $this->publisherTransformer)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
Expand Down
2 changes: 1 addition & 1 deletion examples/User/JsonApi/Resource/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getRelationships($user): array
->setDataAsCallable(function () use ($user) {
return $user["contacts"];
}, $this->contactTransformer)
->omitWhenNotIncluded()
->omitDataWhenNotIncluded()
;
}
];
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApi/Schema/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function setDataAsCallable(callable $callableData, ResourceInterface $res
/**
* @return $this
*/
public function omitWhenNotIncluded()
public function omitDataWhenNotIncluded()
{
$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 @@ -27,7 +27,7 @@ public function getRelationshipData()
return $this->getData();
}

public function isOmitWhenNotIncluded(): bool
public function isOmitDataWhenNotIncluded(): bool
{
return $this->omitDataWhenNotIncluded;
}
Expand Down
13 changes: 6 additions & 7 deletions tests/JsonApi/Schema/Relationship/AbstractRelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

$relationship->omitWhenNotIncluded();
$omit = $relationship->isOmitWhenNotIncluded();
$relationship->omitDataWhenNotIncluded();

$this->assertTrue($omit);
$this->assertTrue($relationship->isOmitDataWhenNotIncluded());
}

/**
Expand Down Expand Up @@ -252,7 +251,7 @@ public function transformWithEmptyData()
public function transformWithEmptyOmittedData()
{
$relationship = $this->createRelationship()
->omitWhenNotIncluded();
->omitDataWhenNotIncluded();

$relationshipObject = $relationship->transform(
new ResourceTransformation(
Expand Down

0 comments on commit 84f7d0d

Please sign in to comment.