Skip to content

Commit

Permalink
Fixed all the clients' models unlink when a single one is removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Dec 4, 2023
1 parent 56f0f35 commit f4f47f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Model/Table/ClientModelTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Monarc\BackOffice\Model\Table;

use Monarc\BackOffice\Model\DbCli;
use Monarc\BackOffice\Model\Entity\Client;
use Monarc\BackOffice\Model\Entity\ClientModel;
use Monarc\Core\Model\Table\AbstractEntityTable;
use Monarc\Core\Service\ConnectedUserService;
Expand All @@ -26,10 +27,13 @@ public function __construct(
parent::__construct($dbService, ClientModel::class, $connectedUserService);
}

public function deleteByModelIds(array $modelIds): void
public function deleteByClientAndModelIds(Client $client, array $modelIds): void
{
$queryBuilder = $this->getRepository()->createQueryBuilder('cm');
$clientModels = $queryBuilder->where($queryBuilder->expr()->in('cm.modelId', array_map('\intval', $modelIds)))
$clientModels = $queryBuilder
->where('cm.client = :client')
->andWhere($queryBuilder->expr()->in('cm.modelId', array_map('\intval', $modelIds)))
->setParameter('client', $client)
->getQuery()
->getResult();

Expand Down
2 changes: 1 addition & 1 deletion src/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function update($id, $data)
$updateData['modelIdsToAdd'][] = $newModelId;
}
if (!empty($updateData['modelIdsToRemove'])) {
$clientModelTable->deleteByModelIds($updateData['modelIdsToRemove']);
$clientModelTable->deleteByClientAndModelIds($entity, $updateData['modelIdsToRemove']);
}
}

Expand Down

0 comments on commit f4f47f4

Please sign in to comment.