Skip to content

Commit

Permalink
bug #25841 [DoctrineBridge] Fix bug when indexBy is meta key in Prope…
Browse files Browse the repository at this point in the history
…rtyInfo\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
  • Loading branch information
nicolas-grekas committed Apr 20, 2018
2 parents d05f0a0 + 583759f commit 733e813
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Expand Up @@ -95,9 +95,19 @@ public function getTypes($class, $property, array $context = array())

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

if (null === $typeOfField) {
$associationMapping = $subMetadata->getAssociationMapping($indexProperty);

/** @var ClassMetadataInfo $subMetadata */
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($indexProperty);
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
}

$collectionKeyType = $this->getPhpType($typeOfField);
}
}
Expand Down
Expand Up @@ -59,6 +59,7 @@ public function testGetProperties()
'foo',
'bar',
'indexedBar',
'indexedFoo',
),
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
);
Expand Down Expand Up @@ -136,6 +137,14 @@ public function typesProvider()
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
))),
array('indexedFoo', array(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')
))),
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
array('customFoo', null),
array('notMapped', null),
Expand Down
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;

Expand Down Expand Up @@ -45,6 +46,11 @@ class DoctrineDummy
*/
protected $indexedBar;

/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="foo", indexBy="foo")
*/
protected $indexedFoo;

/**
* @Column(type="guid")
*/
Expand Down
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;

/**
* @Entity
Expand All @@ -32,4 +33,10 @@ class DoctrineRelation
* @Column(type="guid")
*/
protected $rguid;

/**
* @Column(type="guid")
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
*/
protected $foo;
}

0 comments on commit 733e813

Please sign in to comment.