10000 Merge branch '3.4' into 4.4 · symfony/symfony@cdfa9c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdfa9c2

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: failing test for issue 38861 [DoctrineBridge] indexBy could reference to association columns
2 parents 0ae674a + 6724ca7 commit cdfa9c2

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,24 @@ public function getTypes($class, $property, array $context = [])
107107
$associationMapping = $metadata->getAssociationMapping($property);
108108

109109
if (isset($associationMapping['indexBy'])) {
110-
$indexColumn = $associationMapping['indexBy'];
111110
/** @var ClassMetadataInfo $subMetadata */
112111
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
113-
$typeOfField = $subMetadata->getTypeOfField($subMetadata->getFieldForColumn($indexColumn));
112+
113+
// Check if indexBy value is a property
114+
$fieldName = $associationMapping['indexBy'];
115+
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
116+
$fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
117+
//Not a property, maybe a column name?
118+
if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
119+
//Maybe the column name is the association join column?
120+
$associationMapping = $subMetadata->getAssociationMapping($fieldName);
121+
122+
/** @var ClassMetadataInfo $subMetadata */
123+
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
124+
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
125+
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
126+
}
127+
}
114128

115129
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
116130
return null;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ private function doTestGetProperties(bool $legacy)
7878
$expected = array_merge($expected, [
7979
'foo',
8080
'bar',
81+
'indexedRguid',
8182
'indexedBar',
8283
'indexedFoo',
84+
'indexedBaz',
8385
'indexedByDt',
8486
'indexedByCustomType',
87+
'indexedBuz',
8588
]);
8689

8790
$this->assertEquals(
@@ -190,6 +193,14 @@ public function typesProvider()
190193
new Type(Type::BUILTIN_TYPE_INT),
191194
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
192195
)]],
196+
['indexedRguid', [new Type(
197+
Type::BUILTIN_TYPE_OBJECT,
198+
false,
199+
'Doctrine\Common\Collections\Collection',
200+
true,
201+
new Type(Type::BUILTIN_TYPE_STRING),
202+
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
203+
)]],
193204
['indexedBar', [new Type(
194205
Type::BUILTIN_TYPE_OBJECT,
195206
false,
@@ -206,6 +217,14 @@ public function typesProvider()
206217
new Type(Type::BUILTIN_TYPE_STRING),
207218
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
208219
)]],
220+
['indexedBaz', [new Type(
221+
Type::BUILTIN_TYPE_OBJECT,
222+
false,
223+
Collection::class,
224+
true,
225+
new Type(Type::BUILTIN_TYPE_INT),
226+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
227+
)]],
209228
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
210229
['customFoo', null],
211230
['notMapped', null],
@@ -218,6 +237,14 @@ public function typesProvider()
218237
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
219238
)]],
220239
['indexedByCustomType', null],
240+
['indexedBuz', [new Type(
241+
Type::BUILTIN_TYPE_OBJECT,
242+
false,
243+
Collection::class,
244+
true,
245+
new Type(Type::BUILTIN_TYPE_STRING),
246+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
247+
)]],
221248
];
222249

223250
if (class_exists(Types::class)) {

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

Lines changed: 15 additions & 6293 ; 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
*/
@@ -51,6 +56,11 @@ class DoctrineDummy
5156
*/
5257
protected $indexedFoo;
5358

59+
/**
60+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="baz", indexBy="baz_id")
61+
*/
62+
protected $indexedBaz;
63+
5464
/**
5565
* @Column(type="guid")
5666
*/
@@ -122,4 +132,9 @@ class DoctrineDummy
122132
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="customType", indexBy="customType")
123133
*/
124134
private $indexedByCustomType;
135+
136+
/**
137+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="buzField", indexBy="buzField")
138+
*/
139+
protected $indexedBuz;
125140
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class DoctrineRelation
4040
*/
4141
protected $foo;
4242

43+
/**
44+
* @ManyToOne(targetEntity="DoctrineDummy")
45+
*/
46+
protected $baz;
47+
4348
/**
4449
* @Column(type="datetime")
4550
*/
@@ -49,4 +54,10 @@ class DoctrineRelation
4954
* @Column(type="foo")
5055
*/
5156
private $customType;
57+
58+
/**
59+
* @Column(type="guid", name="different_than_field")
60+
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBuz")
61+
*/
62+
protected $buzField;
5263
}

0 commit comments

Comments
 (0)
0