From 002e20bcfe7e602875c8226032b3c5606f63e5fb Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 25 Aug 2016 10:30:27 +0200 Subject: [PATCH] Fix EntityType->empty_data=null Symfony 3.1, Doctine 2.5, PHP 7, SQL Server With : ``` $builder ->add('users', EntityType::class, array( 'label' => 'Users', 'class' => 'AppBundle\Entity\Users', 'choice_label' => 'name', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('u') ->orderBy('u.name', 'ASC'); }, 'empty_data' => null, 'required' => false )) ``` I got an error : SQLSTATE [42000, 8114]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Eror converting nvarchar datatype to numeric. --- .../Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index 9477d8265529d..3d14a7f969df6 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -146,7 +146,7 @@ public function loadChoicesForValues(array $values, $value = null) // this was tested on, no exception was thrown for such invalid // statements, consequently no test fails when this code is removed. // https://github.com/symfony/symfony/pull/8981#issuecomment-24230557 - if (empty($values)) { + if (empty($values) || $values === array('')) { return array(); }