Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow relationship without requirement of 'data'
  • Loading branch information
josephmcdermott committed Mar 17, 2016
commit bd3755da684049d278d3805b59620140ad8dffe2
6 changes: 5 additions & 1 deletion src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ protected function getIncluded(ElementInterface $element, $includeParent = false

foreach ($resource->getUnfilteredRelationships() as $relationship) {
$includedElement = $relationship->getData();


if (!$includedElement instanceof ElementInterface) {
continue;
}

foreach ($this->getIncluded($includedElement, true) as $child) {
// If this resource is the same as the top-level "data"
// resource, then we don't want it to show up again in the
Expand Down
10 changes: 5 additions & 5 deletions src/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class Relationship
/**
* The data object.
*
* @var ElementInterface
* @var ElementInterface|null
*/
protected $data;

/**
* Create a new relationship.
*
* @param ElementInterface $data
* @param ElementInterface|null $data
*/
public function __construct(ElementInterface $data)
public function __construct(ElementInterface $data = null)
{
$this->data = $data;
}

/**
* Get the data object.
*
* @return ElementInterface
* @return ElementInterface|null
*/
public function getData()
{
Expand All @@ -46,7 +46,7 @@ public function getData()
/**
* Set the data object.
*
* @param ElementInterface $data
* @param ElementInterface|null $data
* @return $this
*/
public function setData($data)
Expand Down
5 changes: 4 additions & 1 deletion src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ protected function buildRelationships()
$relationship = $this->serializer->getRelationship($this->data, $name);

if ($relationship) {
$relationship->getData()->with($nested)->fields($this->fields);
$relationshipData = $relationship->getData();
if ($relationshipData instanceof ElementInterface) {
$relationshipData->with($nested)->fields($this->fields);
}

$relationships[$name] = $relationship;
}
Expand Down