Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ModelManager to support Doctrine\ORM\Query directly #1691

Merged
merged 6 commits into from
Aug 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\ORM\UnitOfWork;
Expand Down Expand Up @@ -208,7 +209,7 @@ public function createQuery(string $class, string $alias = 'o'): BaseProxyQueryI

public function supportsQuery(object $query): bool
{
return $query instanceof ProxyQuery || $query instanceof QueryBuilder;
return $query instanceof ProxyQuery || $query instanceof Query || $query instanceof QueryBuilder;
}

public function executeQuery(object $query)
Expand All @@ -217,18 +218,19 @@ public function executeQuery(object $query)
return $query->getQuery()->execute();
}

if ($query instanceof ProxyQuery) {
if ($query instanceof Query || $query instanceof ProxyQuery) {
djpretzel marked this conversation as resolved.
Show resolved Hide resolved
/** @phpstan-var Paginator<T> $results */
$results = $query->execute();

return $results;
}

throw new \InvalidArgumentException(sprintf(
'Argument 1 passed to %s() must be an instance of %s or %s',
'Argument 1 passed to %s() must be an instance of %s, %s, or %s',
__METHOD__,
QueryBuilder::class,
ProxyQuery::class,
Query::class,
ProxyQuery::class
));
}

Expand Down