From 086c58c716ad1a676f34dcb3f930f343b38820ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 Jun 2015 17:17:34 +0200 Subject: [PATCH] [DoctrineBridge] Bypass the db when no valid identifier is provided in ORMQueryBuilderLoader --- .../Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php | 3 +++ .../Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index 60aece4400..8f135d6258 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -95,6 +95,9 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface } else { $parameterType = Connection::PARAM_STR_ARRAY; } + if (!$values) { + return array(); + } return $qb->andWhere($where) ->getQuery() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 7b68fda055..8fec7584e4 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -56,7 +56,7 @@ class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase $query->expects($this->once()) ->method('setParameter') - ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array(), $expectedType) + ->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array(1, 2), $expectedType) ->willReturn($query); $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') @@ -72,7 +72,7 @@ class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase ->from($classname, 'e'); $loader = new ORMQueryBuilderLoader($qb); - $loader->getEntitiesByIds('id', array()); + $loader->getEntitiesByIds('id', array(1, 2)); } public function testFilterNonIntegerValues()