8000 [DoctrineBridge] Fix bug when indexBy is meta key in PropertyInfo\DoctrineExtractor by insekticid · Pull Request #25841 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Fix bug when indexBy is meta key in PropertyInfo\DoctrineExtractor #25841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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