Skip to content

Commit

Permalink
Fixed the models removals, by correction of the analysis removal and …
Browse files Browse the repository at this point in the history
…the query to fetch only active models.
  • Loading branch information
ruslanbaidan committed Dec 6, 2024
1 parent 82b1423 commit c0305a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Entity/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getAnr(): ?Anr
return $this->anr;
}

public function setAnr(Anr $anr): self
public function setAnr(?Anr $anr): self
{
$this->anr = $anr;

Expand Down
4 changes: 3 additions & 1 deletion src/Service/ModelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ public function delete(int $id): void
/** @var Model $model */
$model = $this->modelTable->findById($id);
$model->setStatus(Model::STATUS_DELETED);
$anr = $model->getAnr();
$model->setAnr(null);

$this->anrTable->remove($model->getAnr(), false);
$this->anrTable->remove($anr);

$this->modelTable->save($model);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Table/ModelTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public function findGenericsAndSpecificsByIds(array $specificModelsIds = []): ar
{
$queryBuilder = $this->getRepository()->createQueryBuilder('m')
->where('m.isGeneric = 1')
->andWhere('m.anr IS NOT NULL');
->andWhere('m.status = ' . Model::STATUS_ACTIVE);

if (!empty($specificModelsIds)) {
$queryBuilder->orWhere($queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('m.isGeneric', 0),
$queryBuilder->expr()->eq('m.status', Model::STATUS_ACTIVE),
$queryBuilder->expr()->in('m.id', array_map('\intval', $specificModelsIds))
));
}
Expand Down

0 comments on commit c0305a5

Please sign in to comment.