diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php new file mode 100644 index 0000000000000..6032fc79ba079 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationKeyEntity.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\Fixtures; + +use Doctrine\ORM\Mapping AS ORM; + +/** + * An entity whose primary key is a foreign key to another entity. + * + * @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities + * @ORM\Entity + */ +class AssociationKeyEntity +{ + /** + * @ORM\Id + * @ORM\OneToOne(targetEntity="SingleIntIdEntity") + * + * @var SingleIntIdEntity + */ + public $single; + + /** + * AssociationKeyEntity constructor. + * + * @param SingleIntIdEntity $single + */ + public function __construct(SingleIntIdEntity $single) + { + $this->single = $single; + } + + public function getName() + { + return $this->single->name; + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 78f10848bccbf..c8ef6f32a08fe 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -20,6 +20,7 @@ use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; +use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity; @@ -42,6 +43,7 @@ class EntityTypeTest extends TypeTestCase const SINGLE_ASSOC_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity'; const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'; const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity'; + const ASSOCIATION_KEY_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity'; /** * @var EntityManager @@ -69,6 +71,7 @@ protected function setUp() $this->em->getClassMetadata(self::SINGLE_ASSOC_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS), + $this->em->getClassMetadata(self::ASSOCIATION_KEY_CLASS), ); try { @@ -580,6 +583,26 @@ public function testSubmitMultipleExpandedWithNegativeIntegerId() $this->assertFalse($field['2']->getData()); } + public function testSubmitAssociationKey() + { + $single = new SingleIntIdEntity(1, 'Foo'); + $assoc = new AssociationKeyEntity($single); + + $this->persist(array($single, $assoc)); + + $field = $this->factory->createNamed('name', 'entity', null, array( + 'multiple' => false, + 'expanded' => false, + 'em' => 'default', + 'class' => self::ASSOCIATION_KEY_CLASS, + 'choice_label' => 'name', + )); + + $field->submit('1'); + + $this->assertSame($assoc, $field->getData()); + } + public function testOverrideChoices() { $entity1 = new SingleIntIdEntity(1, 'Foo');