diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10880Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10880Test.php index f48dc7a74ff..076630b5a20 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10880Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10880Test.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Doctrine\Tests\OrmFunctionalTestCase; @@ -14,6 +15,7 @@ protected function setUp(): void parent::setUp(); $this->setUpEntitySchema([ + GH10880BaseProcess::class, GH10880Process::class, GH10880ProcessOwner::class, GH10880ProcessStage::class, @@ -42,10 +44,10 @@ public function testProcessShouldBeUpdated(): void $this->_em->flush(); $this->_em->clear(); - $ownerLoaded = $this->_em->find(GH10880ProcessOwner::class, $owner->id); + $ownerLoaded = $this->_em->getRepository(GH10880ProcessOwner::class)->find($owner->id); $processLoaded = $ownerLoaded->process; - $stageBLoaded = $this->_em->find(GH10880ProcessStage::class, $stageB->id); + $stageBLoaded = $this->_em->getRepository(GH10880ProcessStage::class)->find($stageB->id); $processLoaded->currentStage = $stageBLoaded; $queryLog = $this->getQueryLog(); @@ -53,7 +55,7 @@ public function testProcessShouldBeUpdated(): void $this->_em->flush(); self::assertCount(1, $queryLog->queries); - self::assertSame('UPDATE GH10880Process SET currentStage_id = ? WHERE id = ?', $queryLog->queries[0]['sql']); + self::assertSame('UPDATE processes SET current_stage = ? WHERE id = ?', $queryLog->queries[0]['sql']); } } @@ -72,17 +74,44 @@ class GH10880ProcessOwner public $id = null; /** - * @ORM\ManyToOne(targetEntity="GH10880Process") + * @ORM\ManyToOne(targetEntity="GH10880Process", cascade={"persist"}, fetch="EAGER") + * @ORM\JoinColumns({ + * @ORM\JoinColumn(name="process_id", referencedColumnName="id", onDelete="SET NULL") + * }) * * @var GH10880Process */ public $process; + } /** * @ORM\Entity */ -class GH10880Process +class GH10880Process extends GH10880BaseProcess +{ + /** + * @ORM\OneToOne(targetEntity="GH10880ProcessOwner") + * @ORM\JoinColumns({ + * @ORM\JoinColumn(name="parent_object_id", referencedColumnName="id", onDelete="CASCADE") + * }) + * + * @var GH10880ProcessOwner + */ + public $owner; + +} + +/** + * @ORM\Entity() + * @ORM\InheritanceType("SINGLE_TABLE") + * @ORM\DiscriminatorColumn(name="process_parent", type="string") + * @ORM\Table(name="processes") + * @ORM\DiscriminatorMap({ + * "process" = "GH10880Process" + * }) + */ +class GH10880BaseProcess { /** * @ORM\Id @@ -94,18 +123,30 @@ class GH10880Process public $id = null; /** - * @ORM\OneToOne(targetEntity="GH10880ProcessOwner") + * @ORM\OneToOne(targetEntity="GH10880ProcessStage", fetch="EAGER") + * @ORM\JoinColumns({ + * @ORM\JoinColumn(name="current_stage", referencedColumnName="id", onDelete="SET NULL") + * }) * - * @var GH10880ProcessOwner + * @var GH10880ProcessStage */ - public $owner; + public $currentStage; /** - * @ORM\OneToOne(targetEntity="GH10880ProcessStage") + * @ORM\OneToMany(targetEntity="GH10880ProcessStage", mappedBy="process", cascade={"all"}, orphanRemoval=true, fetch="EAGER") + * @ORM\JoinColumns({ + * @ORM\JoinColumn(name="id", referencedColumnName="process_id", onDelete="CASCADE") + * }) * - * @var GH10880ProcessStage + * @var Collection */ - public $currentStage; + public $stages; + + /** + * + * @ORM\Column(name="parent_object_id", type="string", length=255, nullable=true) + */ + public $parentObject; } /** @@ -123,7 +164,10 @@ class GH10880ProcessStage public $id = null; /** - * @ORM\ManyToOne(targetEntity="GH10880Process") + * @ORM\ManyToOne(targetEntity="GH10880Process", inversedBy="stages") + * @ORM\JoinColumns({ + * @ORM\JoinColumn(name="process_id", referencedColumnName="id", onDelete="CASCADE") + * }) * * @var GH10880Process */