Skip to content

Commit 1e2367d

Browse files
victormackoxabbuh
authored andcommitted
[DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
1 parent d23b74e commit 1e2367d

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
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/ManagerRegistryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ManagerRegistryTest extends TestCase
1919
{
2020
public static function setUpBeforeClass(): void
2121
{
22-
if (!class_exists(\PHPUnit_Framework_TestCase::class)) {
22+
if (!class_exists(PHPUnit_Framework_TestCase::class)) {
2323
self::markTestSkipped('proxy-manager-bridge is not yet compatible with namespaced phpunit versions.');
2424
}
2525
$test = new PhpDumperTest();

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 <dunglas@gmail.com>
@@ -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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy