Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
* 3.0.x:
  Revert "Merge pull request #11229 from greg0ire/add-columns"
  Add columns for 3.1.x and 4.0x
  Update version ORM from 2 to 3 in docs (#11221)
  Clean up outdated sentence (#11224)
  Update README.md
  Point link to correct upgrade guide (#11220)
  Ignore subclasses without discriminatorValue when generating discriminator column condition SQL (#11200)
  Update branches in README
  • Loading branch information
derrabus committed Feb 7, 2024
2 parents 1051817 + 5a40b99 commit 9fcb8f1
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 15 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
| [3.0.x][3.0] | [2.19.x][2.19] | [2.18.x][2.18] |
|:----------------:|:----------------:|:----------:|
| [![Build status][3.0 image]][3.0] | [![Build status][2.19 image]][2.19] | [![Build status][2.18 image]][2.18] |
| [![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] |
| [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] |
|:------------------------------------------------------:|:------------------------------------------------------:|:-------------------------------------------------------:|:--------------------------------------------------------:|:---------------------------------------------------------:|
| [![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] |
| [![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] |

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

Doctrine ORM is an object-relational mapper for PHP 7.1+ that provides transparent persistence
Doctrine ORM is an object-relational mapper for PHP 8.1+ that provides transparent persistence
for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features
is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL),
inspired by Hibernate's HQL. This provides developers with a powerful alternative to SQL that maintains flexibility
Expand All @@ -18,6 +18,14 @@ without requiring unnecessary code duplication.
* [Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/stable/index.html)


[4.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0.x
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
[3.1 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.1.x
[3.1]: https://github.com/doctrine/orm/tree/3.1.x
[3.1 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.1.x/graph/badge.svg
[3.1 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.1.x
[3.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0.x
[3.0]: https://github.com/doctrine/orm/tree/3.0.x
[3.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.0.x/graph/badge.svg
Expand Down
4 changes: 2 additions & 2 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Welcome to Doctrine 2 ORM's documentation!
Welcome to Doctrine ORM's documentation!
==========================================

The Doctrine documentation is comprised of tutorials, a reference section and
Expand Down Expand Up @@ -93,7 +93,7 @@ Tutorials
Changelogs
----------

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

Cookbook
--------
Expand Down
3 changes: 1 addition & 2 deletions src/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* The EntityManager is the central access point to ORM functionality.
*
* It is a facade to all different ORM subsystems such as UnitOfWork,
* Query Language and Repository API. Instantiation is done through
* the static create() method. The quickest way to obtain a fully
* Query Language and Repository API. The quickest way to obtain a fully
* configured EntityManager is:
*
* use Doctrine\ORM\Tools\ORMSetup;
Expand Down
24 changes: 18 additions & 6 deletions src/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
continue;
}

$sqlTableAlias = $this->useSqlTableAliases
? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.'
: '';

$conn = $this->em->getConnection();
$values = [];

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

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

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

$sqlParts[] = $sqlTableAlias . $class->getDiscriminatorColumn()->name . ' IN (' . implode(', ', $values) . ')';
$values[] = $conn->quote((string) $subclassMetadata->discriminatorValue);
}

if ($values !== []) {
$sqlParts[] = $sqlTableAlias . $class->getDiscriminatorColumn()->name . ' IN (' . implode(', ', $values) . ')';
} else {
$sqlParts[] = '1=0'; // impossible condition
}
}

$sql = implode(' AND ', $sqlParts);
Expand Down
81 changes: 81 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH11199Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;

class GH11199Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH11199Root::class,
GH11199Parent::class,
GH11199Foo::class,
GH11199Baz::class,
GH11199AbstractLeaf::class,
]);
}

public static function dqlStatements(): Generator
{
yield ['SELECT e FROM ' . GH11199Root::class . ' e', "/WHERE g0_.asset_type IN \('root', 'foo', 'baz'\)$/"];
yield ['SELECT e FROM ' . GH11199Parent::class . ' e', "/WHERE g0_.asset_type IN \('foo'\)$/"];
yield ['SELECT e FROM ' . GH11199Foo::class . ' e', "/WHERE g0_.asset_type IN \('foo'\)$/"];
yield ['SELECT e FROM ' . GH11199Baz::class . ' e', "/WHERE g0_.asset_type IN \('baz'\)$/"];
yield ['SELECT e FROM ' . GH11199AbstractLeaf::class . ' e', '/WHERE 1=0/'];
}

#[DataProvider('dqlStatements')]
public function testGH11199(string $dql, string $expectedDiscriminatorValues): void
{
$query = $this->_em->createQuery($dql);
$sql = $query->getSQL();

self::assertMatchesRegularExpression($expectedDiscriminatorValues, $sql);
}
}

#[ORM\Entity]
#[ORM\Table(name: 'gh11199')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'asset_type', type: 'string')]
#[ORM\DiscriminatorMap([
'root' => GH11199Root::class,
'foo' => GH11199Foo::class,
'baz' => GH11199Baz::class,
])]
class GH11199Root
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column(type: 'integer')]
private int|null $id = null;
}

#[ORM\Entity]
abstract class GH11199Parent extends GH11199Root
{
}

#[ORM\Entity]
class GH11199Foo extends GH11199Parent
{
}

#[ORM\Entity]
class GH11199Baz extends GH11199Root
{
}

#[ORM\Entity]
abstract class GH11199AbstractLeaf extends GH11199Root
{
}

0 comments on commit 9fcb8f1

Please sign in to comment.