diff --git a/src/JsonApi/Schema/Relationship/AbstractRelationship.php b/src/JsonApi/Schema/Relationship/AbstractRelationship.php index ade4e830..cdb51248 100644 --- a/src/JsonApi/Schema/Relationship/AbstractRelationship.php +++ b/src/JsonApi/Schema/Relationship/AbstractRelationship.php @@ -36,7 +36,7 @@ abstract class AbstractRelationship * @param \WoohooLabs\Yin\JsonApi\Transformer\Transformation $transformation * @param string $relationshipName * @param array $defaultRelationships - * @return array + * @return array|null */ abstract protected function transformData( Transformation $transformation, @@ -121,7 +121,8 @@ public function transform( $transformation->basePath, $relationshipName, $defaultRelationships - ) + ) || + $transformation->fetchedRelationship === $relationshipName ) { $transformedData = $this->transformData($transformation, $relationshipName, $defaultRelationships); } else { @@ -178,7 +179,7 @@ protected function transformResource( $transformation->data->addIncludedResource( $this->resourceTransformer->transformToResource($transformation, $domainObject) ); - + $transformation->basePath = $basePath; } diff --git a/src/JsonApi/Transformer/AbstractResourceTransformer.php b/src/JsonApi/Transformer/AbstractResourceTransformer.php index 7219dd9c..e4a994a6 100644 --- a/src/JsonApi/Transformer/AbstractResourceTransformer.php +++ b/src/JsonApi/Transformer/AbstractResourceTransformer.php @@ -201,6 +201,7 @@ protected function transformRelationshipObject( array $defaultRelationships, array $additionalMeta = [] ) { + $transformation->setFetchedRelationship($relationshipName); $resourceType = $this->getType($domainObject); if ($transformation->request->isIncludedField($resourceType, $relationshipName) === false && diff --git a/src/JsonApi/Transformer/Transformation.php b/src/JsonApi/Transformer/Transformation.php index eff3141d..ebbfe93d 100644 --- a/src/JsonApi/Transformer/Transformation.php +++ b/src/JsonApi/Transformer/Transformation.php @@ -27,6 +27,11 @@ class Transformation */ public $basePath; + /** + * @var string|null + */ + public $fetchedRelationship; + /** * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request * @param \WoohooLabs\Yin\JsonApi\Schema\Data\DataInterface $data @@ -76,4 +81,20 @@ public function getBasePath() { return $this->basePath; } + + /** + * @return string + */ + public function getFetchedRelationship() + { + return $this->fetchedRelationship; + } + + /** + * @param string $fetchedRelationship + */ + public function setFetchedRelationship($fetchedRelationship) + { + $this->fetchedRelationship = $fetchedRelationship; + } }