[DoctrineBundle] Fixed: CollectionToChoiceTransformer should accept null values
This commit is contained in:
parent
3564b86ee9
commit
e4eb7f720b
@ -71,6 +71,10 @@ class CollectionToChoiceTransformer extends BaseValueTransformer
|
||||
*/
|
||||
public function transform($value)
|
||||
{
|
||||
if (null === $value) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$metadata = $this->getOption('em')->getClassMetadata($this->getOption('className'));
|
||||
$reflField = $metadata->getReflectionProperty($metadata->identifier[0]);
|
||||
|
||||
@ -78,6 +82,7 @@ class CollectionToChoiceTransformer extends BaseValueTransformer
|
||||
foreach ($value AS $object) {
|
||||
$ids[] = $reflField->getValue($object);
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
@ -68,6 +68,13 @@ class CollectionToChoiceTransformerTest extends \Symfony\Bundle\DoctrineBundle\T
|
||||
$this->assertEquals(array(), $ids);
|
||||
}
|
||||
|
||||
public function testTransformNull()
|
||||
{
|
||||
$transformer = $this->createTransformer();
|
||||
|
||||
$this->assertEquals(array(), $transformer->transform(null));
|
||||
}
|
||||
|
||||
public function createTagCollection()
|
||||
{
|
||||
$tags = new ArrayCollection();
|
||||
|
Reference in New Issue
Block a user