Skip to content

Commit 5a40b99

Browse files
committed
Merge branch '2.18.x' into 3.0.x
* 2.18.x: Point link to correct upgrade guide (doctrine#11220) Ignore subclasses without discriminatorValue when generating discriminator column condition SQL (doctrine#11200) Update branches in README
2 parents 94144e1 + 40fbbf4 commit 5a40b99

File tree

4 files changed

+112
-11
lines changed

4 files changed

+112
-11
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| [3.0.x][3.0] | [2.19.x][2.19] | [2.18.x][2.18] |
2-
|:----------------:|:----------------:|:----------:|
3-
| [![Build status][3.0 image]][3.0] | [![Build status][2.19 image]][2.19] | [![Build status][2.18 image]][2.18] |
4-
| [![Coverage Status][3.0 coverage image]][3.0 coverage]| [![Coverage Status][2.19 coverage image]][2.19 coverage] | [![Coverage Status][2.18 coverage image]][2.18 coverage] |
1+
| [4.0.x][4.0] | [3.1.x][3.1] | [3.0.x][3.0] | [2.19.x][2.19] | [2.18.x][2.18] |
2+
|:------------------------------------------------------:|:------------------------------------------------------:|:-------------------------------------------------------:|:--------------------------------------------------------:|:---------------------------------------------------------:|
3+
| [![Build status][4.0 image]][4.0] | [![Build status][3.1 image]][3.1] | [![Build status][3.0 image]][3.0] | [![Build status][2.19 image]][2.19] | [![Build status][2.18 image]][2.18] |
4+
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.1 coverage image]][3.1 coverage] | [![Coverage Status][3.0 coverage image]][3.0 coverage] | [![Coverage Status][2.19 coverage image]][2.19 coverage] | [![Coverage Status][2.18 coverage image]][2.18 coverage] |
55

66
[<h1 align="center">🇺🇦 UKRAINE NEEDS YOUR HELP NOW!</h1>](https://www.doctrine-project.org/stop-war.html)
77

@@ -18,6 +18,14 @@ without requiring unnecessary code duplication.
1818
* [Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/stable/index.html)
1919

2020

21+
[4.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0.x
22+
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
23+
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
24+
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
25+
[3.1 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.1.x
26+
[3.1]: https://github.com/doctrine/orm/tree/3.1.x
27+
[3.1 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.1.x/graph/badge.svg
28+
[3.1 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.1.x
2129
[3.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0.x
2230
[3.0]: https://github.com/doctrine/orm/tree/3.0.x
2331
[3.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.0.x/graph/badge.svg

docs/en/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Tutorials
9393
Changelogs
9494
----------
9595

96-
* `Upgrade <https://github.com/doctrine/doctrine2/blob/master/UPGRADE.md>`_
96+
* `Upgrade <https://github.com/doctrine/orm/blob/HEAD/UPGRADE.md>`_
9797

9898
Cookbook
9999
--------

src/Query/SqlWalker.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
376376
continue;
377377
}
378378

379+
$sqlTableAlias = $this->useSqlTableAliases
380+
? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.'
381+
: '';
382+
379383
$conn = $this->em->getConnection();
380384
$values = [];
381385

@@ -384,14 +388,22 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
384388
}
385389

386390
foreach ($class->subClasses as $subclassName) {
387-
$values[] = $conn->quote((string) $this->em->getClassMetadata($subclassName)->discriminatorValue);
388-
}
391+
$subclassMetadata = $this->em->getClassMetadata($subclassName);
389392

390-
$sqlTableAlias = $this->useSqlTableAliases
391-
? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.'
392-
: '';
393+
// Abstract entity classes show up in the list of subClasses, but may be omitted
394+
// from the discriminator map. In that case, they have a null discriminator value.
395+
if ($subclassMetadata->discriminatorValue === null) {
396+
continue;
397+
}
393398

394-
$sqlParts[] = $sqlTableAlias . $class->getDiscriminatorColumn()->name . ' IN (' . implode(', ', $values) . ')';
399+
$values[] = $conn->quote((string) $subclassMetadata->discriminatorValue);
400+
}
401+
402+
if ($values !== []) {
403+
$sqlParts[] = $sqlTableAlias . $class->getDiscriminatorColumn()->name . ' IN (' . implode(', ', $values) . ')';
404+
} else {
405+
$sqlParts[] = '1=0'; // impossible condition
406+
}
395407
}
396408

397409
$sql = implode(' AND ', $sqlParts);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
use Doctrine\Tests\OrmFunctionalTestCase;
9+
use Generator;
10+
use PHPUnit\Framework\Attributes\DataProvider;
11+
12+
class GH11199Test extends OrmFunctionalTestCase
13+
{
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
$this->setUpEntitySchema([
19+
GH11199Root::class,
20+
GH11199Parent::class,
21+
GH11199Foo::class,
22+
GH11199Baz::class,
23+
GH11199AbstractLeaf::class,
24+
]);
25+
}
26+
27+
public static function dqlStatements(): Generator
28+
{
29+
yield ['SELECT e FROM ' . GH11199Root::class . ' e', "/WHERE g0_.asset_type IN \('root', 'foo', 'baz'\)$/"];
30+
yield ['SELECT e FROM ' . GH11199Parent::class . ' e', "/WHERE g0_.asset_type IN \('foo'\)$/"];
31+
yield ['SELECT e FROM ' . GH11199Foo::class . ' e', "/WHERE g0_.asset_type IN \('foo'\)$/"];
32+
yield ['SELECT e FROM ' . GH11199Baz::class . ' e', "/WHERE g0_.asset_type IN \('baz'\)$/"];
33+
yield ['SELECT e FROM ' . GH11199AbstractLeaf::class . ' e', '/WHERE 1=0/'];
34+
}
35+
36+
#[DataProvider('dqlStatements')]
37+
public function testGH11199(string $dql, string $expectedDiscriminatorValues): void
38+
{
39+
$query = $this->_em->createQuery($dql);
40+
$sql = $query->getSQL();
41+
42+
self::assertMatchesRegularExpression($expectedDiscriminatorValues, $sql);
43+
}
44+
}
45+
46+
#[ORM\Entity]
47+
#[ORM\Table(name: 'gh11199')]
48+
#[ORM\InheritanceType('SINGLE_TABLE')]
49+
#[ORM\DiscriminatorColumn(name: 'asset_type', type: 'string')]
50+
#[ORM\DiscriminatorMap([
51+
'root' => GH11199Root::class,
52+
'foo' => GH11199Foo::class,
53+
'baz' => GH11199Baz::class,
54+
])]
55+
class GH11199Root
56+
{
57+
#[ORM\Id]
58+
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
59+
#[ORM\Column(type: 'integer')]
60+
private int|null $id = null;
61+
}
62+
63+
#[ORM\Entity]
64+
abstract class GH11199Parent extends GH11199Root
65+
{
66+
}
67+
68+
#[ORM\Entity]
69+
class GH11199Foo extends GH11199Parent
70+
{
71+
}
72+
73+
#[ORM\Entity]
74+
class GH11199Baz extends GH11199Root
75+
{
76+
}
77+
78+
#[ORM\Entity]
79+
abstract class GH11199AbstractLeaf extends GH11199Root
80+
{
81+
}

0 commit comments

Comments
 (0)