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

Skip to content

Commit a3fa8e1

Browse files
victormackonicolas-grekas
authored andcommitted
[DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
1 parent 85af7a2 commit a3fa8e1

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ public function getTypes(string $class, string $property, array $context = [])
104104
/** @var ClassMetadataInfo $subMetadata */
105105
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
106106
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
107-
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
107+
108+
//Not a property, maybe a column name?
109+
if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
110+
$fieldName = $subMetadata->getFieldForColumn($indexProperty);
111+
$typeOfField = $subMetadata->getTypeOfField($fieldName);
112+
}
108113
}
109114
}
110115

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function testGetProperties()
7171
'indexedByDt',
7272
'indexedByCustomType',
7373
'indexedBuz',
74+
'dummyGeneratedValueList',
7475
]);
7576

7677
$this->assertEquals(
@@ -198,6 +199,14 @@ public function typesProvider()
198199
new Type(Type::BUILTIN_TYPE_STRING),
199200
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
200201
)]],
202+
['dummyGeneratedValueList', [new Type(
203+
Type::BUILTIN_TYPE_OBJECT,
204+
false,
205+
'Doctrine\Common\Collections\Collection',
206+
true,
207+
new Type(Type::BUILTIN_TYPE_INT),
208+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
209+
)]],
201210
['json', null],
202211
];
203212

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class DoctrineDummy
138138
*/
139139
protected $indexedBuz;
140140

141+
/**
142+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dummyRelation", indexBy="gen_value_col_id", orphanRemoval=true)
143+
*/
144+
protected $dummyGeneratedValueList;
145+
141146
/**
142147
* @Column(type="json", nullable=true)
143148
*/

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)