Merge branch '5.1' into 5.x
* 5.1: failing test for issue 38861 [DoctrineBridge] indexBy could reference to association columns
This commit is contained in:
commit
a9895ea72b
@ -89,10 +89,24 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
|
|||||||
$associationMapping = $metadata->getAssociationMapping($property);
|
$associationMapping = $metadata->getAssociationMapping($property);
|
||||||
|
|
||||||
if (isset($associationMapping['indexBy'])) {
|
if (isset($associationMapping['indexBy'])) {
|
||||||
$indexColumn = $associationMapping['indexBy'];
|
|
||||||
/** @var ClassMetadataInfo $subMetadata */
|
/** @var ClassMetadataInfo $subMetadata */
|
||||||
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
||||||
$typeOfField = $subMetadata->getTypeOfField($subMetadata->getFieldForColumn($indexColumn));
|
|
||||||
|
// Check if indexBy value is a property
|
||||||
|
$fieldName = $associationMapping['indexBy'];
|
||||||
|
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
|
||||||
|
$fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
|
||||||
|
//Not a property, maybe a column name?
|
||||||
|
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
|
||||||
|
//Maybe the column name is the association join column?
|
||||||
|
$associationMapping = $subMetadata->getAssociationMapping($fieldName);
|
||||||
|
|
||||||
|
/** @var ClassMetadataInfo $subMetadata */
|
||||||
|
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
|
||||||
|
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
||||||
|
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
|
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -64,10 +64,13 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
$expected = array_merge($expected, [
|
$expected = array_merge($expected, [
|
||||||
'foo',
|
'foo',
|
||||||
'bar',
|
'bar',
|
||||||
|
'indexedRguid',
|
||||||
'indexedBar',
|
'indexedBar',
|
||||||
'indexedFoo',
|
'indexedFoo',
|
||||||
|
'indexedBaz',
|
||||||
'indexedByDt',
|
'indexedByDt',
|
||||||
'indexedByCustomType',
|
'indexedByCustomType',
|
||||||
|
'indexedBuz',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -143,6 +146,14 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
new Type(Type::BUILTIN_TYPE_INT),
|
new Type(Type::BUILTIN_TYPE_INT),
|
||||||
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
||||||
)]],
|
)]],
|
||||||
|
['indexedRguid', [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')
|
||||||
|
)]],
|
||||||
['indexedBar', [new Type(
|
['indexedBar', [new Type(
|
||||||
Type::BUILTIN_TYPE_OBJECT,
|
Type::BUILTIN_TYPE_OBJECT,
|
||||||
false,
|
false,
|
||||||
@ -159,6 +170,14 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
new Type(Type::BUILTIN_TYPE_STRING),
|
new Type(Type::BUILTIN_TYPE_STRING),
|
||||||
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
||||||
)]],
|
)]],
|
||||||
|
['indexedBaz', [new Type(
|
||||||
|
Type::BUILTIN_TYPE_OBJECT,
|
||||||
|
false,
|
||||||
|
Collection::class,
|
||||||
|
true,
|
||||||
|
new Type(Type::BUILTIN_TYPE_INT),
|
||||||
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
|
||||||
|
)]],
|
||||||
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
|
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
|
||||||
['customFoo', null],
|
['customFoo', null],
|
||||||
['notMapped', null],
|
['notMapped', null],
|
||||||
@ -171,6 +190,14 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
|
||||||
)]],
|
)]],
|
||||||
['indexedByCustomType', null],
|
['indexedByCustomType', null],
|
||||||
|
['indexedBuz', [new Type(
|
||||||
|
Type::BUILTIN_TYPE_OBJECT,
|
||||||
|
false,
|
||||||
|
Collection::class,
|
||||||
|
true,
|
||||||
|
new Type(Type::BUILTIN_TYPE_STRING),
|
||||||
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
|
||||||
|
)]],
|
||||||
['json', null],
|
['json', null],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -41,6 +41,11 @@ class DoctrineDummy
|
|||||||
*/
|
*/
|
||||||
public $bar;
|
public $bar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid")
|
||||||
|
*/
|
||||||
|
protected $indexedRguid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid_column")
|
* @ManyToMany(targetEntity="DoctrineRelation", indexBy="rguid_column")
|
||||||
*/
|
*/
|
||||||
@ -51,6 +56,11 @@ class DoctrineDummy
|
|||||||
*/
|
*/
|
||||||
protected $indexedFoo;
|
protected $indexedFoo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="baz", indexBy="baz_id")
|
||||||
|
*/
|
||||||
|
protected $indexedBaz;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Column(type="guid")
|
* @Column(type="guid")
|
||||||
*/
|
*/
|
||||||
@ -123,6 +133,11 @@ class DoctrineDummy
|
|||||||
*/
|
*/
|
||||||
private $indexedByCustomType;
|
private $indexedByCustomType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="buzField", indexBy="buzField")
|
||||||
|
*/
|
||||||
|
protected $indexedBuz;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Column(type="json", nullable=true)
|
* @Column(type="json", nullable=true)
|
||||||
*/
|
*/
|
||||||
|
@ -40,6 +40,11 @@ class DoctrineRelation
|
|||||||
*/
|
*/
|
||||||
protected $foo;
|
protected $foo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ManyToOne(targetEntity="DoctrineDummy")
|
||||||
|
*/
|
||||||
|
protected $baz;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Column(type="datetime")
|
* @Column(type="datetime")
|
||||||
*/
|
*/
|
||||||
@ -49,4 +54,10 @@ class DoctrineRelation
|
|||||||
* @Column(type="foo")
|
* @Column(type="foo")
|
||||||
*/
|
*/
|
||||||
private $customType;
|
private $customType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="guid", name="different_than_field")
|
||||||
|
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBuz")
|
||||||
|
*/
|
||||||
|
protected $buzField;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user