Skip to content

[WCM][DoctrineBridge] Fix UniqueEntity interaction with inheritance #16981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 changes: 6 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ Yaml

* The `!!php/object` tag to indicate dumped PHP objects was removed in favor of
the `!php/object` tag.

Doctrine Bridge
---

* The `UniqueEntity` constraints now requires a `target` property when loaded
with the `StaticMethodLoader`.
7 changes: 7 additions & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

3.2.0
-----

* fixed `UniqueEntity` interaction with inheritance
* deprecated `UniqueEntity` constraints without a target (possible only if
`StaticMethodLoader` or a custom constraint loader is used)

3.1.0
-----

Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/ChildEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures;

use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;

/** @Entity */
class ChildEntity extends SingleIntIdEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\Entity;

/**
* @Entity
*/
class GoodEntity extends UpperTransient
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\Entity;

/**
* @Entity
*/
class InstanceEntity extends LowerEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\Entity;

/**
* @Entity
*/
class LowerEntity extends LowerTransient
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\MappedSuperclass;

/** @MappedSuperclass */
class LowerMappedSuperClass extends GoodEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

class LowerTransient extends LowerMappedSuperClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\Entity;

/**
* @Entity
*/
class SideEntity extends SideTransient
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\MappedSuperclass;

/** @MappedSuperclass */
class SideMappedSuperClass extends GoodEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

class SideTransient extends SideMappedSuperClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\MappedSuperclass;

/** @MappedSuperclass */
class TargetMappedSuperClass extends TopEntity
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

class TargetTransient extends TargetMappedSuperClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\InheritanceType;

/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({
* "top" = "TopEntity",
* "good" = "GoodEntity",
* "low" = "LowEntity",
* "side" = "SideEntity",
* "inst" = "InstanceEntity",
* })
*
* The point of this hierarchy is to test the selection of the repository
* by the UniqueEntityValidator. This hierarchy provides:
* - A top entity which is too high in the inheritance chain to be selected
* - Both a transient and a mapped super class targets
* - Upper mapped super and transient classes which should not be selected
* - A good Entity which is intended to provide the repo
* - A side branch including one of each Entity, Mapped Super and Transient
* - A lower part including one of each Entity, Mapped Super and Transient
* which are not intended to be selected since they lower than the GoodEntity
* - An InstanceEntity which is intended to be validated
*/
class TopEntity
{
/** @Id @Column(type="integer") */
protected $id;

/** @Column(type="string", nullable=true) */
public $name;

public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

use Doctrine\ORM\Mapping\MappedSuperclass;

/** @MappedSuperclass */
class UpperMappedSuperClass extends TargetTransient
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures\HighestEntity;

class UpperTransient extends UpperMappedSuperClass
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@

use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\InheritanceType;

/** @Entity */
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"parent" = "SingleIntIdEntity", "child" = "ChildEntity"})
*/
class SingleIntIdEntity
{
/** @Id @Column(type="integer") */
Expand Down
Loading