symfony/symfony — Issue #3446: [Form] Submit empty multiple entity choice -> error
Author: chmielot
Created: 2012-02-24 20:53:00+00:00
State: open

This is my form element:

```
$form->add($this->factory->createNamed('entity', 'job', null, array(
'class' => 'PDB\PlanningBundle\Entity\Job',
'property' => 'name',
'required' => false,
'multiple' => true,
'query_builder' => function(JobRepository $er) use ($project) {
...
```

If there is is nothing selected in this choice field, the field name isn't submitted and `null` is bound to the field. All leads to the following stack trace:
https://gist.github.com/1903637

In my opinion this is a problem of `ChoicesToValuesTransformer` in `reverseTransform` method where it should be

```
if (empty($array)) {
return array();
}
```

instead of

```
if (null === $array) {
return array();
}
```

and I'd add this to the tests:

```
public function testReverseTransformEmptyArray()
{
$this->assertSame(array(), $this->transformer->reverseTransform(array()));
}
```

This fixes my problem at least.
Do you agree? Then I'd submit a patch. How to add a pull request to this ticket?