Skip to content

Commit

Permalink
#100. Fix exception on deleteBulk
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Aug 18, 2018
1 parent 39c0175 commit 8b05e2a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/blocks/EntitiesTrait.php
Expand Up @@ -10,6 +10,7 @@
use rjapi\extension\ApiController;
use rjapi\extension\BaseFormRequest;
use rjapi\extension\BaseModel;
use rjapi\extension\JSONApiInterface;
use rjapi\helpers\Classes;
use rjapi\helpers\ConfigHelper as conf;
use rjapi\helpers\ConfigOptions;
Expand Down Expand Up @@ -128,7 +129,7 @@ protected function mutateBulk(array $jsonApiAttributes) : ResourceAbstract
DB::beginTransaction();
foreach ($jsonApiAttributes as $jsonObject) {

$model = $this->getEntity($jsonObject['id']);
$model = $this->getEntity($jsonObject[JSONApiInterface::CONTENT_ID]);

// FSM transition check
if ($this->configOptions->isStateMachine() === true) {
Expand Down Expand Up @@ -169,11 +170,11 @@ public function removeBulk(array $jsonApiAttributes) : void
DB::beginTransaction();

foreach ($jsonApiAttributes as $jsonObject) {
$model = $this->getEntity($jsonObject['id']);
$model = $this->getEntity($jsonObject[JSONApiInterface::CONTENT_ID]);

if ($model === null) {
DB::rollBack();
throw new AttributesException('There is no such id: ' . $jsonObject['id'] . ' - transaction is rolled back.');
throw new AttributesException('There is no such id: ' . $jsonObject[JSONApiInterface::CONTENT_ID] . ' or model was already deleted - transaction has been rolled back.');
}

$model->delete();
Expand Down

0 comments on commit 8b05e2a

Please sign in to comment.