8000 fix(): indexBy value can be a property · symfony/symfony@6b58fa4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b58fa4

Browse files
fix(): indexBy value can be a property
1 parent 6f1a7f4 commit 6b58fa4

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

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

Lines 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

Lines 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

Lines 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