Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fdf8b71

Browse files
committedOct 14, 2021
Add a test case using reserved words in column names
1 parent e313d01 commit fdf8b71

5 files changed

+95
-3
lines changed
 

‎doctrine-mapping.xsd

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
</xs:choice>
271271
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
272272
<xs:attribute name="type" type="xs:NMTOKEN" default="string" />
273-
<xs:attribute name="column" type="xs:NMTOKEN" />
273+
<xs:attribute name="column" type="xs:string" />
274274
<xs:attribute name="length" type="xs:NMTOKEN" />
275275
<xs:attribute name="unique" type="xs:boolean" default="false" />
276276
<xs:attribute name="nullable" type="xs:boolean" default="false" />
@@ -359,7 +359,7 @@
359359
</xs:choice>
360360
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
361361
<xs:attribute name="type" type="xs:NMTOKEN" />
362-
<xs:attribute name="column" type="xs:NMTOKEN" />
362+
<xs:attribute name="column" type="xs:string" />
363363
<xs:attribute name="length" type="xs:NMTOKEN" />
364364
<xs:attribute name="association-key" type="xs:boolean" default="false" />
365365
<xs:attribute name="column-definition" type="xs:string" />
@@ -538,7 +538,7 @@
538538
<xs:element name="options" type="orm:options" minOccurs="0" />
539539
</xs:choice>
540540
<xs:attribute name="type" type="xs:NMTOKEN" default="string" />
541-
<xs:attribute name="column" type="xs:NMTOKEN" />
541+
<xs:attribute name="column" type="xs:string" />
542542
<xs:attribute name="length" type="xs:NMTOKEN" />
543543
<xs:attribute name="unique" type="xs:boolean" default="false" />
544544
<xs:attribute name="nullable" type="xs:boolean" default="false" />

‎tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,13 @@ public function testDiscriminatorColumnDefaultName(): void
11191119
$class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
11201120
self::assertEquals('dtype', $class->discriminatorColumn['name']);
11211121
}
1122+
1123+
public function testReservedWordInTableColumn(): void
1124+
{
1125+
$metadata = $this->createClassMetadata(ReservedWordInTableColumn::class);
1126+
1127+
self::assertSame('count', $metadata->getFieldMapping('count')['columnName']);
1128+
}
11221129
}
11231130

11241131
/**
@@ -1774,3 +1781,42 @@ class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1 extends SingleTa
17741781
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2 extends SingleTableEntityIncompleteDiscriminatorColumnMapping
17751782
{
17761783
}
1784+
1785+
/** @Entity */
1786+
#[ORM\Entity]
1787+
class ReservedWordInTableColumn
1788+
{
1789+
/**
1790+
* @var int
1791+
* @Id
1792+
* @Column(type="integer")
1793+
* @GeneratedValue(strategy="NONE")
1794+
*/
1795+
#[ORM\Id, ORM\Column(type: 'integer'), ORM\GeneratedValue(strategy: 'NONE')]
1796+
public $id;
1797+
1798+
/**
1799+
* @var string|null
1800+
* @Column(name="`count`", type="integer")
1801+
*/
1802+
#[ORM\Column(name: '`count`', type: 'integer')]
1803+
public $count;
1804+
1805+
public static function loadMetadata(ClassMetadataInfo $metadata): void
1806+
{
1807+
$metadata->mapField(
1808+
[
1809+
'id' => true,
1810+
'fieldName' => 'id',
1811+
'type' => 'integer',
1812+
]
1813+
);
1814+
$metadata->mapField(
1815+
[
1816+
'fieldName' => 'count',
1817+
'type' => 'integer',
1818+
'columnName' => '`count`',
1819+
]
1820+
);
1821+
}
1822+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$metadata->mapField(
6+
[
7+
'id' => true,
8+
'fieldName' => 'id',
9+
'type' => 'integer',
10+
]
11+
);
12+
$metadata->mapField(
13+
[
14+
'fieldName' => 'count',
15+
'type' => 'integer',
16+
'columnName' => '`count`',
17+
]
18+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
6+
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
7+
8+
<entity name="Doctrine\Tests\ORM\Mapping\ReservedWordInTableColumn">
9+
10+
<id name="id" type="integer" column="id">
11+
<generator strategy="NONE"/>
12+
</id>
13+
14+
<field name="count" column="`count`" type="integer"/>
15+
16+
</entity>
17+
18+
</doctrine-mapping>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Doctrine\Tests\ORM\Mapping\ReservedWordInTableColumn:
2+
type: entity
3+
id:
4+
id:
5+
generator:
6+
strategy: NONE
7+
fields:
8+
count:
9+
type: integer
10+
column: '`count`'

0 commit comments

Comments
 (0)
Please sign in to comment.