From 8f8aff92f2019e66cf106747ad58f30bc905992b Mon Sep 17 00:00:00 2001 From: mctekk Date: Sat, 1 Jun 2019 10:51:09 -0400 Subject: [PATCH] fix issue with updating custom fields --- composer.json | 14 ++++--------- src/Contracts/Api/CrudBehaviorTrait.php | 2 +- .../Api/CrudCustomFieldsBehaviorTrait.php | 21 ++++++++++++++----- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 22c52ed..d511220 100755 --- a/composer.json +++ b/composer.json @@ -7,27 +7,21 @@ "email": "max@mctekk.com" }], "require": { - "php": ">=7.1", + "php": ">=7.2", "ext-phalcon": ">=3.0.0", "vlucas/phpdotenv": "^2.0", "phalcon/incubator": ">=3.0.0", - "baka/database": "^0.1", + "baka/database": "^0.5", "baka/elasticsearch": "^1.0", "elasticsearch/elasticsearch": "^6.1", - "guzzlehttp/guzzle": "^6.3", - "robmorgan/phinx": "^0.10", - "odan/phinx-migrations-generator": "dev-master" + "guzzlehttp/guzzle": "^6.3" }, "require-dev": { "codeception/codeception": "^2.4", "codeception/verify": "*", "vlucas/phpdotenv": "^2.0", "phalcon/incubator": "~3.3", - "dmkit/phalcon-jwt-auth": "dev-master", - "elasticsearch/elasticsearch": "^6.1", - "baka/database": "^0.1", - "odan/phinx-migrations-generator": "dev-master" - + "odan/phinx-migrations-generator": "^4.0" }, "autoload": { "psr-4": { diff --git a/src/Contracts/Api/CrudBehaviorTrait.php b/src/Contracts/Api/CrudBehaviorTrait.php index 80a0ff6..df531c7 100644 --- a/src/Contracts/Api/CrudBehaviorTrait.php +++ b/src/Contracts/Api/CrudBehaviorTrait.php @@ -169,7 +169,7 @@ protected function processIndex() public function getById($id): Response { //find the info - $record = $this->model::getByIdOrFail($id); + $record = $this->model::findFirstOrFail($id); //get the results and append its relationships $result = $this->appendRelationshipsToResult($this->request, $record); diff --git a/src/Contracts/Api/CrudCustomFieldsBehaviorTrait.php b/src/Contracts/Api/CrudCustomFieldsBehaviorTrait.php index 0aaf242..de210f4 100644 --- a/src/Contracts/Api/CrudCustomFieldsBehaviorTrait.php +++ b/src/Contracts/Api/CrudCustomFieldsBehaviorTrait.php @@ -28,10 +28,21 @@ protected function appendRelationshipsToResult(Request $request, $results) // Relationships, but we have to change it to sparo full implementation if ($request->hasQuery('relationships')) { $relationships = $request->getQuery('relationships', 'string'); - + $results = is_object($results) ? RequestUriToElasticSearch::parseRelationShips($relationships, $results) : $results; } + return $results; + } + + /** + * Process output + * + * @param mixed $results + * @return mixed + */ + protected function processOutput($results) + { return is_object($results) ? $results->toFullArray() : $results; } @@ -43,11 +54,11 @@ protected function appendRelationshipsToResult(Request $request, $results) */ protected function processCreate(Request $request): ModelInterface { - $this->processCreateParent($request); - //set the custom fields to create $this->model->setCustomFields($request->getPostData()); + $this->processCreateParent($request); + return $this->model; } @@ -61,11 +72,11 @@ protected function processCreate(Request $request): ModelInterface */ protected function processEdit(Request $request, ModelInterface $record): ModelInterface { - $record = $this->processEditParent($request, $record); - //set the custom fields to update $record->setCustomFields($request->getPutData()); + $record = $this->processEditParent($request, $record); + return $record; }