Skip to content

Commit 6c3aa2e

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [Security] Replace message data in JSON security error response [DI] Skip deprecated definitions in CheckTypeDeclarationsPass [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
2 parents 4f60b83 + fae7b53 commit 6c3aa2e

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

PropertyInfo/DoctrineExtractor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ public function getTypes(string $class, string $property, array $context = [])
110110
/** @var ClassMetadataInfo $subMetadata */
111111
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
112112
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
113-
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
113+
114+
//Not a property, maybe a column name?
115+
if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
116+
$fieldName = $subMetadata->getFieldForColumn($indexProperty);
117+
$typeOfField = $subMetadata->getTypeOfField($fieldName);
118+
}
114119
}
115120
}
116121

Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testGetProperties()
7575
'indexedByDt',
7676
'indexedByCustomType',
7777
'indexedBuz',
78+
'dummyGeneratedValueList',
7879
]);
7980

8081
$this->assertEquals(
@@ -202,6 +203,15 @@ public function typesProvider()
202203
new Type(Type::BUILTIN_TYPE_STRING),
203204
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
204205
)]],
206+
['dummyGeneratedValueList', [new Type(
207+
Type::BUILTIN_TYPE_OBJECT,
208+
false,
209+
'Doctrine\Common\Collections\Collection',
210+
true,
211+
new Type(Type::BUILTIN_TYPE_INT),
212+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
213+
)]],
214+
['json', null],
205215
];
206216

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

Tests/PropertyInfo/Fixtures/DoctrineDummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ class DoctrineDummy
137137
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="buzField", indexBy="buzField")
138138
*/
139139
protected $indexedBuz;
140+
141+
/**
142+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dummyRelation", indexBy="gen_value_col_id", orphanRemoval=true)
143+
*/
144+
protected $dummyGeneratedValueList;
140145
}

Tests/PropertyInfo/Fixtures/DoctrineGeneratedValue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\GeneratedValue;
1717
use Doctrine\ORM\Mapping\Id;
18+
use Doctrine\ORM\Mapping\OneToMany;
1819

1920
/**
2021
* @author Kévin Dunglas <[email protected]>
@@ -34,4 +35,15 @@ class DoctrineGeneratedValue
3435
* @Column
3536
*/
3637
public $foo;
38+
39+
/**
40+
* @var int
41+
* @Column(type="integer", name="gen_value_col_id")
42+
*/
43+
public $valueId;
44+
45+
/**
46+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="generatedValueRelation", indexBy="rguid_column", orphanRemoval=true)
47+
*/
48+
protected $relationList;
3749
}

Tests/PropertyInfo/Fixtures/DoctrineRelation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\Id;
1717
use Doctrine\ORM\Mapping\ManyToOne;
18+
use Doctrine\ORM\Mapping\JoinColumn;
1819

1920
/**
2021
* @Entity
@@ -60,4 +61,15 @@ class DoctrineRelation
6061
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBuz")
6162
*/
6263
protected $buzField;
64+
65+
/**
66+
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="dummyGeneratedValueList")
67+
*/
68+
private $dummyRelation;
69+
70+
/**
71+
* @ManyToOne(targetEntity="DoctrineGeneratedValue", inversedBy="relationList")
72+
* @JoinColumn(name="gen_value_col_id", referencedColumnName="gen_value_col_id")
73+
*/
74+
private $generatedValueRelation;
6375
}

0 commit comments

Comments
 (0)