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 a0b6778

Browse filesBrowse files
fix(): indexBy value can be a property
1 parent c153328 commit a0b6778
Copy full SHA for a0b6778

File tree

3 files changed

+27
-10
lines changed
Filter options

3 files changed

+27
-10
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
+14-10Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ public function getTypes($class, $property, array $context = [])
112112
if (isset($associationMapping['indexBy'])) {
113113
/** @var ClassMetadataInfo $subMetadata */
114114
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
115-
$fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
116-
$typeOfField = $subMetadata->getTypeOfField($fieldName);
117115

118-
// Maybe $fieldName is an association
119-
if (null === $typeOfField) {
120-
$associationMapping = $subMetadata->getAssociationMapping($fieldName);
121-
122-
/** @var ClassMetadataInfo $subMetadata */
123-
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
124-
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
125-
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
116+
// Check if indexBy value is a property
117+
$fieldName = $associationMapping['indexBy'];
118+
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
119+
$fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
120+
//Not a property, maybe a column name?
121+
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
122+
//Maybe the column name is the association join column?
123+
$associationMapping = $subMetadata->getAssociationMapping($fieldName);
124+
125+
/** @var ClassMetadataInfo $subMetadata */
126+
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
127+
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
128+
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
129+
}
126130
}
127131

128132
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {

‎src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ public function typesProvider()
152152
new Type(Type::BUILTIN_TYPE_INT),
153153
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
154154
)]],
155+
['indexedRguid', [new Type(
156+
Type::BUILTIN_TYPE_OBJECT,
157+
false,
158+
'Doctrine\Common\Collections\Collection',
159+
true,
160+
new Type(Type::BUILTIN_TYPE_STRING),
161+
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
162+
)]],
155163
['indexedBar', [new Type(
156164
Type::BUILTIN_TYPE_OBJECT,
157165
false,

‎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
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class DoctrineDummy
4141
*/
4242
public $bar;
4343

44+
/**
45+
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid")
46+
*/
47+
protected $indexedRguid;
48+
4449
/**
4550
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid_column")
4651
*/

0 commit comments

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