From 545277e425b285a28f9790921a0542d5f1fe5f0c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 7 Aug 2019 16:29:04 +0000 Subject: [PATCH] wip --- src/Handler/Concerns/SavesData.php | 18 ++++++++++++------ src/Handler/Index.php | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Handler/Concerns/SavesData.php b/src/Handler/Concerns/SavesData.php index b233dcd..2dd6c97 100644 --- a/src/Handler/Concerns/SavesData.php +++ b/src/Handler/Concerns/SavesData.php @@ -132,12 +132,18 @@ trait SavesData $value = &$data[$field->location][$name]; - if ($field instanceof Schema\HasOne) { - $value = $this->getModelForIdentifier($request, $value['data']); - } elseif ($field instanceof Schema\HasMany) { - $value = array_map(function ($identifier) use ($request) { - return $this->getModelForIdentifier($request, $identifier); - }, $value['data']); + if ($field instanceof Schema\Relationship) { + $value = $value['data']; + + if ($value) { + if ($field instanceof Schema\HasOne) { + $value = $this->getModelForIdentifier($request, $value); + } elseif ($field instanceof Schema\HasMany) { + $value = array_map(function ($identifier) use ($request) { + return $this->getModelForIdentifier($request, $identifier); + }, $value); + } + } } } } diff --git a/src/Handler/Index.php b/src/Handler/Index.php index 47de1eb..e94ed04 100644 --- a/src/Handler/Index.php +++ b/src/Handler/Index.php @@ -81,7 +81,7 @@ class Index implements RequestHandlerInterface $paginationLinks[] = new Link\PrevLink($this->buildUrl($request, $params)); } - if ($schema->countable) { + if ($schema->countable && $schema->paginate) { $total = $adapter->count($query); $members[] = new Meta('total', $total);