Skip to content

Commit

Permalink
Fix non unique SplObjectIds bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozhidar Hristov committed Nov 11, 2020
1 parent b76460a commit 4f7782d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions FiltersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

trait FiltersTrait
{
private array $appendedFilters = [];
private array $filters;

abstract public function getFilters(): array;
Expand Down Expand Up @@ -38,6 +37,7 @@ abstract public function createQueryBuilder($alias, $indexBy = null);
public function createQueryBuilderByFilters($alias, $filterBy): QueryBuilder
{
$queryBuilder = $this->createQueryBuilder($alias);
$queryBuilder->filters = [];

foreach ($filterBy as $filter => $value) {
$this->appendFilter($queryBuilder, $alias, $filter, $value);
Expand All @@ -48,8 +48,7 @@ public function createQueryBuilderByFilters($alias, $filterBy): QueryBuilder

public function appendFilter(QueryBuilder $queryBuilder, string $alias, string $filterName, $value): bool
{
$queryBuilderId = spl_object_id($queryBuilder);
if (isset($this->appendedFilters[$queryBuilderId][$filterName])) {
if (isset($queryBuilder->filters[$filterName])) {
return false;
}

Expand All @@ -60,7 +59,7 @@ public function appendFilter(QueryBuilder $queryBuilder, string $alias, string $
call_user_func_array($filter, [$queryBuilder, $alias, $value]);
}

return $this->appendedFilters[$queryBuilderId][$filterName] = true;
return $queryBuilder->filters[$filterName] = true;
}

public function findOneByFilters(array $filterBy)
Expand Down

0 comments on commit 4f7782d

Please sign in to comment.