Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03642b8

Browse files
committed
[Form] Fix a BC break in the entity
1 parent 095bfd6 commit 03642b8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function createChoiceLabel($choice)
8787
*/
8888
public static function createChoiceName($choice, $key, $value)
8989
{
90-
return (string) $value;
90+
return str_replace('-', '_', (string) $value);
9191
}
9292

9393
/**

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,31 @@ public function testSubmitMultipleExpanded()
495495
$this->assertSame('3', $field['3']->getViewData());
496496
}
497497

498+
public function testSubmitMultipleExpandedWithNegativeIntegerId()
499+
{
500+
$entity1 = new SingleIntIdEntity(-1, 'Foo');
501+
$entity2 = new SingleIntIdEntity(2, 'Bar');
502+
503+
$this->persist(array($entity1, $entity2));
504+
505+
$field = $this->factory->createNamed('name', 'entity', null, array(
506+
'multiple' => true,
507+
'expanded' => true,
508+
'em' => 'default',
509+
'class' => self::SINGLE_IDENT_CLASS,
510+
'choice_label' => 'name',
511+
));
512+
513+
$field->submit(array('-1'));
514+
515+
$expected = new ArrayCollection(array($entity1));
516+
517+
$this->assertTrue($field->isSynchronized());
518+
$this->assertEquals($expected, $field->getData());
519+
$this->assertTrue($field['_1']->getData());
520+
$this->assertFalse($field['2']->getData());
521+
}
522+
498523
public function testOverrideChoices()
499524
{
500525
$entity1 = new SingleIntIdEntity(1, 'Foo');

0 commit comments

Comments
 (0)