Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8076c2f

Browse files
committed
bug #39667 [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity (victormacko)
This PR was merged into the 4.4 branch. Discussion ---------- [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | none | License | MIT | Doc PR | bug-fix only In Symfony 4.4.17 (I think), using ManyToMany in doctrine, along with indexBy="person_id" (in the related entity, which has a property of "id" (which in-turn uses the db column "person_id" worked as expected. When upgrading to Symfony 5.2.1, this stops working. This change continues on from issue #37982 to fix a further edge case. Commits ------- 472eab1 [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
2 parents dd142e2 + 472eab1 commit 8076c2f

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ public function getTypes($class, $property, array $context = [])
122122
/** @var ClassMetadataInfo $subMetadata */
123123
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
124124
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
125-
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
125+
126+
//Not a property, maybe a column name?
127+
if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
128+
$fieldName = $subMetadata->getFieldForColumn($indexProperty);
129+
$typeOfField = $subMetadata->getTypeOfField($fieldName);
130+
}
126131
}
127132
}
128133

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private function doTestGetProperties(bool $legacy)
8585
'indexedByDt',
8686
'indexedByCustomType',
8787
'indexedBuz',
88+
'dummyGeneratedValueList',
8889
]);
8990

9091
$this->assertEquals(
@@ -245,6 +246,15 @@ public function typesProvider()
245246
new Type(Type::BUILTIN_TYPE_STRING),
246247
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
247248
)]],
249+
['dummyGeneratedValueList', [new Type(
250+
Type::BUILTIN_TYPE_OBJECT,
251+
false,
252+
'Doctrine\Common\Collections\Collection',
253+
true,
254+
new Type(Type::BUILTIN_TYPE_INT),
255+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
256+
)]],
257+
['json', null],
248258
];
249259

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

src/Symfony/Bridge/Doctrine/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
}

src/Symfony/Bridge/Doctrine/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
}

src/Symfony/Bridge/Doctrine/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)