diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index 4dc71a571..471ab283e 100644 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -18,6 +18,7 @@ use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\OptimisticLockException; @@ -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 AbstractQuery || $query instanceof QueryBuilder; } public function executeQuery(object $query) @@ -217,6 +218,10 @@ public function executeQuery(object $query) return $query->getQuery()->execute(); } + if ($query instanceof AbstractQuery) { + return $query->execute(); + } + if ($query instanceof ProxyQuery) { /** @phpstan-var Paginator $results */ $results = $query->execute(); @@ -225,10 +230,11 @@ public function executeQuery(object $query) } 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, + AbstractQuery::class, + ProxyQuery::class )); } diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index 075adb822..009a26030 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\OptimisticLockException; @@ -149,6 +150,7 @@ public function testSupportsQuery(bool $expected, object $object): void public function supportsQueryDataProvider(): iterable { yield [true, new ProxyQuery($this->createMock(QueryBuilder::class))]; + yield [true, $this->createMock(AbstractQuery::class)]; yield [true, $this->createMock(QueryBuilder::class)]; yield [false, new \stdClass()]; }