Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6717f2c

Browse filesBrowse files
committed
bug #20051 Fix indexBy type extraction (lemoinem)
This PR was merged into the 2.8 branch. Discussion ---------- Fix indexBy type extraction | Q | A | ------------- | --- | Branch? | 2.8+ | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A Bug found and patched by @ksom Since 3008228, the Doctrine Bridge's PropertyInfo Extractor tries to extract the type of the key in an indexed association. However, as you can see in 3008228#diff-7a8fb8072d57f95ea6e37898b05895bcR91, the extractor was using the metadata of the class containing the association instead of the target entity's metadata to retrieve the type of the index. The tests were green because in 3008228#diff-c7e914ed89ceffd939733efe08c039c2R44, the property used to `indexBy` was present in the classes on both sides of the relation with the same type. Once the test is fixed (by renaming the property in the targetEntity), the test provided at 3008228#diff-1b2e044d1df011c00caf802a07895bdbR88 gives the error 1) Symfony\Bridge\Doctrine\PropertyInfo\Tests\DoctrineExtractorTest::testExtract with data set #9 ('indexedBar', array(Symfony\Component\PropertyInfo\Type Object (...))) InvalidArgumentException: "" is not a valid PHP type. The fix is to fetch the metadata of the target entity and check there for the property type. Commits ------- 138c6e3 Fix indexBy type extraction
2 parents aef5008 + 138c6e3 commit 6717f2c
Copy full SHA for 6717f2c

File tree

3 files changed

+4
-3
lines changed
Filter options

3 files changed

+4
-3
lines changed

‎src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public function getTypes($class, $property, array $context = array())
8888

8989
if (isset($associationMapping['indexBy'])) {
9090
$indexProperty = $associationMapping['indexBy'];
91-
$typeOfField = $metadata->getTypeOfField($indexProperty);
91+
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
92+
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
9293

9394
$collectionKeyType = $this->getPhpType($typeOfField);
9495
}

‎src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DoctrineDummy
4141
public $bar;
4242

4343
/**
44-
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="guid")
44+
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid")
4545
*/
4646
protected $indexedBar;
4747

‎src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ class DoctrineRelation
3131
/**
3232
* @Column(type="guid")
3333
*/
34-
protected $guid;
34+
protected $rguid;
3535
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.