Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 733e813

Browse files
bug #25841 [DoctrineBridge] Fix bug when indexBy is meta key in PropertyInfo\DoctrineExtractor (insekticid)
This PR was submitted for the 3.4 branch but it was merged into the 2.8 branch instead (closes #25841). Discussion ---------- [DoctrineBridge] Fix bug when indexBy is meta key in PropertyInfo\DoctrineExtractor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #25834 <!-- #-prefixed issue number(s), if any --> | License | MIT @dunglas could you check it? <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. - Replace this comment by a description of what your PR is solving. --> Commits ------- 583759f PropertyInfo\DoctrineExtractor - There is bug when indexBy is meta key
2 parents d05f0a0 + 583759f commit 733e813

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,19 @@ public function getTypes($class, $property, array $context = array())
9595

9696
if (isset($associationMapping['indexBy'])) {
9797
$indexProperty = $associationMapping['indexBy'];
98+
/** @var ClassMetadataInfo $subMetadata */
9899
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
99100
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
100101

102+
if (null === $typeOfField) {
103+
$associationMapping = $subMetadata->getAssociationMapping($indexProperty);
104+
105+
/** @var ClassMetadataInfo $subMetadata */
106+
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($indexProperty);
107+
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
108+
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
109+
}
110+
101111
$collectionKeyType = $this->getPhpType($typeOfField);
102112
}
103113
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function testGetProperties()
5959
'foo',
6060
'bar',
6161
'indexedBar',
62+
'indexedFoo',
6263
),
6364
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
6465
);
@@ -136,6 +137,14 @@ public function typesProvider()
136137
new Type(Type::BUILTIN_TYPE_STRING),
137138
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
138139
))),
140+
array('indexedFoo', array(new Type(
141+
Type::BUILTIN_TYPE_OBJECT,
142+
false,
143+
'Doctrine\Common\Collections\Collection',
144+
true,
145+
new Type(Type::BUILTIN_TYPE_STRING),
146+
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
147+
))),
139148
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
140149
array('customFoo', null),
141150
array('notMapped', null),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\ORM\Mapping\Column;
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\Id;
17+
use Doctrine\ORM\Mapping\OneToMany;
1718
use Doctrine\ORM\Mapping\ManyToMany;
1819
use Doctrine\ORM\Mapping\ManyToOne;
1920

@@ -45,6 +46,11 @@ class DoctrineDummy
4546
*/
4647
protected $indexedBar;
4748

49+
/**
50+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="foo", indexBy="foo")
51+
*/
52+
protected $indexedFoo;
53+
4854
/**
4955
* @Column(type="guid")
5056
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\ORM\Mapping\Column;
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\Id;
17+
use Doctrine\ORM\Mapping\ManyToOne;
1718

1819
/**
1920
* @Entity
@@ -32,4 +33,10 @@ class DoctrineRelation
3233
* @Column(type="guid")
3334
*/
3435
protected $rguid;
36+
37+
/**
38+
* @Column(type="guid")
39+
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
40+
*/
41+
protected $foo;
3542
}

0 commit comments

Comments
 (0)