-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prohibits class typo in the discriminator map (#8122)
* Prevents incorrect table aliases to be generated When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See #8112 for the consequence of such typo. * Controls growing rate of the abstract test class * Fixes incorrect test case The Cube class must be autoloaded with the correct case, otherwise composer autoloader will complain. * Removes non architecture compliant code See https://github.com/doctrine/orm/pull/8122/files#r423952247 * Ensures discriminator map is case sensitive
- Loading branch information
Showing
7 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap; | ||
|
||
/** @Entity */ | ||
final class Cube extends Shape | ||
{ | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Shape.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
|
||
/** | ||
* @Entity | ||
* @InheritanceType("SINGLE_TABLE") | ||
* @DiscriminatorMap({"cube" = cube::class}) | ||
* @DiscriminatorColumn(name="discr", length=32, type="string") | ||
*/ | ||
abstract class Shape | ||
{ | ||
/** @Id @Column(type="string") @GeneratedValue(strategy="AUTO") */ | ||
public $id; | ||
|
||
public static function loadMetadata(ClassMetadataInfo $metadata) | ||
{ | ||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); | ||
$metadata->setDiscriminatorColumn([ | ||
'name' => 'discr', | ||
'type' => 'string', | ||
'length' => 32, | ||
]); | ||
$metadata->setDiscriminatorMap([ | ||
'cube' => cube::class, | ||
]); | ||
$metadata->mapField([ | ||
'fieldName' => 'id', | ||
'type' => 'string', | ||
'length' => null, | ||
'precision' => 0, | ||
'scale' => 0, | ||
'nullable' => false, | ||
'unique' => false, | ||
'id' => true, | ||
'columnName' => 'id', | ||
]); | ||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...trine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube; | ||
|
||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); | ||
$metadata->setDiscriminatorColumn([ | ||
'name' => 'discr', | ||
'type' => 'string', | ||
'length' => 32, | ||
]); | ||
$metadata->setDiscriminatorMap([ | ||
'cube' => cube::class, | ||
]); | ||
$metadata->mapField([ | ||
'fieldName' => 'id', | ||
'type' => 'string', | ||
'length' => null, | ||
'precision' => 0, | ||
'scale' => 0, | ||
'nullable' => false, | ||
'unique' => false, | ||
'id' => true, | ||
'columnName' => 'id', | ||
]); | ||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); |
15 changes: 15 additions & 0 deletions
15
...e/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
<entity name="Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape" inheritance-type="SINGLE_TABLE"> | ||
<discriminator-column name="discr" type="string" length="32" /> | ||
<discriminator-map> | ||
<discriminator-mapping value="cube" class="Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube" /> | ||
</discriminator-map> | ||
<id name="id" type="integer" column="id"> | ||
<generator strategy="AUTO" /> | ||
</id> | ||
</entity> | ||
</doctrine-mapping> |
14 changes: 14 additions & 0 deletions
14
.../Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape: | ||
type: entity | ||
inheritanceType: SINGLE_TABLE | ||
discriminatorMap: | ||
cube: Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube | ||
discriminatorColumn: | ||
type: string | ||
name: discr | ||
length: 32 | ||
id: | ||
id: | ||
type: integer | ||
generator: | ||
strategy: AUTO |