PropertyInfo\DoctrineExtractor - There is bug when indexBy is meta key

This commit is contained in:
insekticid 2018-03-31 01:03:42 +02:00 committed by Nicolas Grekas
parent d05f0a0e03
commit 583759f0b6
4 changed files with 32 additions and 0 deletions

View File

@ -95,9 +95,19 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
if (isset($associationMapping['indexBy'])) {
$indexProperty = $associationMapping['indexBy'];
/** @var ClassMetadataInfo $subMetadata */
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
if (null === $typeOfField) {
$associationMapping = $subMetadata->getAssociationMapping($indexProperty);
/** @var ClassMetadataInfo $subMetadata */
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($indexProperty);
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
}
$collectionKeyType = $this->getPhpType($typeOfField);
}
}

View File

@ -59,6 +59,7 @@ class DoctrineExtractorTest extends TestCase
'foo',
'bar',
'indexedBar',
'indexedFoo',
),
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
);
@ -136,6 +137,14 @@ class DoctrineExtractorTest extends TestCase
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
))),
array('indexedFoo', array(new Type(
Type::BUILTIN_TYPE_OBJECT,
false,
'Doctrine\Common\Collections\Collection',
true,
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
))),
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
array('customFoo', null),
array('notMapped', null),

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
@ -45,6 +46,11 @@ class DoctrineDummy
*/
protected $indexedBar;
/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="foo", indexBy="foo")
*/
protected $indexedFoo;
/**
* @Column(type="guid")
*/

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
/**
* @Entity
@ -32,4 +33,10 @@ class DoctrineRelation
* @Column(type="guid")
*/
protected $rguid;
/**
* @Column(type="guid")
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
*/
protected $foo;
}