|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use Doctrine\Common\Collections\ArrayCollection; |
| 8 | +use Doctrine\Common\Collections\Collection; |
| 9 | +use Doctrine\ORM\Exception\ORMException; |
| 10 | +use Doctrine\ORM\Mapping as ORM; |
| 11 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 12 | + |
| 13 | +class GH11501Test extends OrmFunctionalTestCase |
| 14 | +{ |
| 15 | + protected function setUp(): void |
| 16 | + { |
| 17 | + parent::setUp(); |
| 18 | + |
| 19 | + $this->setUpEntitySchema([ |
| 20 | + GH11501AbstractTestEntity::class, |
| 21 | + GH11501TestEntityOne::class, |
| 22 | + GH11501TestEntityTwo::class, |
| 23 | + GH11501TestEntityHolder::class, |
| 24 | + ]); |
| 25 | + } |
| 26 | + |
| 27 | + /** @throws ORMException */ |
| 28 | + public function testDeleteOneToManyCollectionWithSingleTableInheritance(): void |
| 29 | + { |
| 30 | + $testEntityOne = new GH11501TestEntityOne(); |
| 31 | + $testEntityTwo = new GH11501TestEntityTwo(); |
| 32 | + $testEntityHolder = new GH11501TestEntityHolder(); |
| 33 | + |
| 34 | + $testEntityOne->testEntityHolder = $testEntityHolder; |
| 35 | + $testEntityHolder->testEntities->add($testEntityOne); |
| 36 | + |
| 37 | + $testEntityTwo->testEntityHolder = $testEntityHolder; |
| 38 | + $testEntityHolder->testEntities->add($testEntityTwo); |
| 39 | + |
| 40 | + $em = $this->getEntityManager(); |
| 41 | + $em->persist($testEntityOne); |
| 42 | + $em->persist($testEntityTwo); |
| 43 | + $em->persist($testEntityHolder); |
| 44 | + $em->flush(); |
| 45 | + |
| 46 | + $testEntityHolder->testEntities = new ArrayCollection(); |
| 47 | + $em->persist($testEntityHolder); |
| 48 | + $em->flush(); |
| 49 | + $em->refresh($testEntityHolder); |
| 50 | + |
| 51 | + static::assertEmpty($testEntityHolder->testEntities->toArray(), 'All records should have been deleted'); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +#[ORM\Entity] |
| 56 | +#[ORM\Table(name: 'one_to_many_single_table_inheritance_test_entities_parent_join')] |
| 57 | +#[ORM\InheritanceType('SINGLE_TABLE')] |
| 58 | +#[ORM\DiscriminatorColumn(name: 'type', type: 'string')] |
| 59 | +#[ORM\DiscriminatorMap([ |
| 60 | + 'test_entity_one' => 'GH11501TestEntityOne', |
| 61 | + 'test_entity_two' => 'GH11501TestEntityTwo', |
| 62 | +])] |
| 63 | +class GH11501AbstractTestEntity |
| 64 | +{ |
| 65 | + #[ORM\Id] |
| 66 | + #[ORM\Column(type: 'integer')] |
| 67 | + #[ORM\GeneratedValue] |
| 68 | + public int $id; |
| 69 | + |
| 70 | + #[ORM\ManyToOne(targetEntity: 'GH11501TestEntityHolder', inversedBy: 'testEntities')] |
| 71 | + #[ORM\JoinColumn(name: 'test_entity_holder_id', referencedColumnName: 'id')] |
| 72 | + public GH11501TestEntityHolder $testEntityHolder; |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +#[ORM\Entity] |
| 77 | +class GH11501TestEntityOne extends GH11501AbstractTestEntity |
| 78 | +{ |
| 79 | +} |
| 80 | + |
| 81 | +#[ORM\Entity] |
| 82 | +class GH11501TestEntityTwo extends GH11501AbstractTestEntity |
| 83 | +{ |
| 84 | +} |
| 85 | + |
| 86 | +#[ORM\Entity] |
| 87 | +class GH11501TestEntityHolder |
| 88 | +{ |
| 89 | + #[ORM\Id] |
| 90 | + #[ORM\Column(type: 'integer')] |
| 91 | + #[ORM\GeneratedValue] |
| 92 | + public int $id; |
| 93 | + |
| 94 | + #[ORM\OneToMany( |
| 95 | + targetEntity: 'GH11501AbstractTestEntity', |
| 96 | + mappedBy: 'testEntityHolder', |
| 97 | + orphanRemoval: true, |
| 98 | + )] |
| 99 | + public Collection $testEntities; |
| 100 | + |
| 101 | + public function __construct() |
| 102 | + { |
| 103 | + $this->testEntities = new ArrayCollection(); |
| 104 | + } |
| 105 | +} |
0 commit comments