forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OneToManyPersister::deleteEntityCollection missing discriminator …
…column/value. (doctrineGH-11500)
- Loading branch information
Showing
2 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
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,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\ORM\PersistentCollection; | ||
use Doctrine\ORM\Persisters\Collection\OneToManyPersister; | ||
use Doctrine\Tests\Mocks\ConnectionMock; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function array_pop; | ||
use function assert; | ||
|
||
class GH11500Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
GH11500AbstractTestEntity::class, | ||
GH11500TestEntity::class, | ||
GH11500TestEntityHolder::class, | ||
]); | ||
} | ||
|
||
public function testDeleteOneToManyCollectionWithSingleTableInheritance(): void | ||
{ | ||
$em = $this->getTestEntityManager(); | ||
$conn = $em->getConnection(); | ||
assert($conn instanceof ConnectionMock); | ||
|
||
$testEntity = new GH11500TestEntity(); | ||
$testEntityHolder = new GH11500TestEntityHolder(); | ||
|
||
$testEntity->testEntityHolder = $testEntityHolder; | ||
$testEntityHolder->testEntities->add($testEntity); | ||
|
||
$em->persist($testEntity); | ||
$em->persist($testEntityHolder); | ||
$em->flush(); | ||
|
||
assert($testEntityHolder->testEntities instanceof PersistentCollection); | ||
|
||
$persister = new OneToManyPersister($em); | ||
$persister->delete($testEntityHolder->testEntities); | ||
|
||
$updates = $conn->getExecuteStatements(); | ||
$lastStatement = array_pop($updates); | ||
|
||
self::assertEquals('DELETE FROM one_to_many_single_table_inheritance_test_entities WHERE test_entity_holder_id = ? AND type = ?', $lastStatement['sql']); | ||
self::assertEquals('test_entity', $lastStatement['params'][1] ?? null); | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="one_to_many_single_table_inheritance_test_entities") | ||
* @ORM\InheritanceType("SINGLE_TABLE") | ||
* @ORM\DiscriminatorColumn(name="type", type="string") | ||
* @ORM\DiscriminatorMap({"test_entity"="GH11500TestEntity"}) | ||
*/ | ||
class GH11500AbstractTestEntity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
} | ||
|
||
|
||
/** @ORM\Entity */ | ||
class GH11500TestEntity extends GH11500AbstractTestEntity | ||
{ | ||
/** | ||
* @ORM\ManyToOne(targetEntity="GH11500TestEntityHolder", inversedBy="testEntities") | ||
* @ORM\JoinColumn(name="test_entity_holder_id", referencedColumnName="id") | ||
* | ||
* @var GH11500TestEntityHolder | ||
*/ | ||
public $testEntityHolder; | ||
} | ||
|
||
/** @ORM\Entity */ | ||
class GH11500TestEntityHolder | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="GH11500TestEntity", mappedBy="testEntityHolder", orphanRemoval=true) | ||
* | ||
* @var Collection | ||
*/ | ||
public $testEntities; | ||
|
||
public function __construct() | ||
{ | ||
$this->testEntities = new ArrayCollection(); | ||
} | ||
} |