Skip to content

Commit

Permalink
Merge pull request #23 from bakaphp/feature-version-05
Browse files Browse the repository at this point in the history
fix issue with updating custom fields
  • Loading branch information
kaioken authored Jun 3, 2019
2 parents c87c8e7 + 8f8aff9 commit 928e0d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
14 changes: 4 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@
"email": "[email protected]"
}],
"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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Api/CrudBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 16 additions & 5 deletions src/Contracts/Api/CrudCustomFieldsBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 928e0d3

Please sign in to comment.