Skip to content

Commit

Permalink
Merge pull request #27 from sander3/single-relationship-bugfix
Browse files Browse the repository at this point in the history
Resolves #26
  • Loading branch information
sander3 authored Apr 14, 2019
2 parents 03bfb49 + 6cfe612 commit 957036e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Portable.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,21 @@ private function getPortableRelations(array $relations)
*/
private function loadPortableRelation(string $relation)
{
$this->attributes[$relation] = $this
->$relation()
$instance = $this->$relation();

$collection = $instance
->get()
->transform(function ($item) {
return $item->portable();
});

$class = class_basename(get_class($instance));

if (in_array($class, ['HasOne', 'BelongsTo'])) {
$collection = $collection->first();
}

$this->attributes[$relation] = $collection;
}

/**
Expand Down

0 comments on commit 957036e

Please sign in to comment.