From b5fb0c50e44e26fb8769067c63eaf955bad60a69 Mon Sep 17 00:00:00 2001 From: Bart Wach Date: Thu, 29 Oct 2020 21:30:43 +0100 Subject: [PATCH 1/3] failing test for issue 38861 --- .../Tests/PropertyInfo/DoctrineExtractorTest.php | 9 +++++++++ .../Tests/PropertyInfo/Fixtures/DoctrineDummy.php | 5 +++++ .../Tests/PropertyInfo/Fixtures/DoctrineRelation.php | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index b9abd03347e83..ace89f8d8e674 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -76,6 +76,7 @@ public function testGetProperties() 'indexedFoo', 'indexedByDt', 'indexedByCustomType', + 'indexedBaz' ]); $this->assertEquals( @@ -179,6 +180,14 @@ public function typesProvider() new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class) )]], ['indexedByCustomType', null], + ['indexedBaz', [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') + )]] ]; if (class_exists(Types::class)) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php index 568efce33d382..e834889096a5a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php @@ -122,4 +122,9 @@ class DoctrineDummy * @OneToMany(targetEntity="DoctrineRelation", mappedBy="customType", indexBy="customType") */ private $indexedByCustomType; + + /** + * @OneToMany(targetEntity="DoctrineRelation", mappedBy="bazField", indexBy="bazField") + */ + protected $indexedBaz; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php index e480ca9d777ba..01390729f19a8 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php @@ -49,4 +49,10 @@ class DoctrineRelation * @Column(type="foo") */ private $customType; + + /** + * @Column(type="guid", name="different_than_field") + * @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBaz") + */ + protected $bazField; } From c57530bade941edd5d2702edc6eb8317edafe984 Mon Sep 17 00:00:00 2001 From: Bart Wach Date: Thu, 29 Oct 2020 21:31:01 +0100 Subject: [PATCH 2/3] fix for issue 38861 --- .../Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 0cfdc8768c9fe..03341e17a8f44 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -110,10 +110,15 @@ public function getTypes($class, $property, array $context = []) $associationMapping = $metadata->getAssociationMapping($property); if (isset($associationMapping['indexBy'])) { - $indexColumn = $associationMapping['indexBy']; + $indexField = $associationMapping['indexBy']; /** @var ClassMetadataInfo $subMetadata */ $subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']); - $typeOfField = $subMetadata->getTypeOfField($subMetadata->getFieldForColumn($indexColumn)); + + $typeOfField = $subMetadata->getTypeOfField($indexField); + + if (!$typeOfField) { + $typeOfField = $subMetadata->getTypeOfField($subMetadata->getFieldForColumn($indexField)); + } if (!$collectionKeyType = $this->getPhpType($typeOfField)) { return null; From 51bd84b1f719db626e40fc2eb38415e40414cb5e Mon Sep 17 00:00:00 2001 From: Bart Wach Date: Thu, 29 Oct 2020 22:03:15 +0100 Subject: [PATCH 3/3] fabbot patch --- .../Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index ace89f8d8e674..62cb4612ef4cf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -76,7 +76,7 @@ public function testGetProperties() 'indexedFoo', 'indexedByDt', 'indexedByCustomType', - 'indexedBaz' + 'indexedBaz', ]); $this->assertEquals( @@ -187,7 +187,7 @@ public function typesProvider() true, new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation') - )]] + )]], ]; if (class_exists(Types::class)) {