From f1c77277f35cbd7db2e49220aaaa115f89f71755 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 25 May 2021 23:45:08 +0200 Subject: [PATCH] Handle parent deletion in associated tables (MainBundle) --- src/Bundle/ChillMainBundle/Entity/Address.php | 2 +- .../migrations/Version20210525144016.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210525144016.php diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 36eda09c2..2003a7910 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -137,7 +137,7 @@ class Address * @var ThirdParty|null * * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty") - * @ORM\JoinColumn(nullable=true) + * @ORM\JoinColumn(nullable=true, onDelete="SET NULL") */ private $linkedToThirdParty; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210525144016.php b/src/Bundle/ChillMainBundle/migrations/Version20210525144016.php new file mode 100644 index 000000000..3be8d9ea1 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210525144016.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE chill_main_address DROP CONSTRAINT FK_165051F6114B8DD9'); + $this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT FK_165051F6114B8DD9 FOREIGN KEY (linkedToThirdParty_id) REFERENCES chill_3party.third_party (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_address DROP CONSTRAINT fk_165051f6114b8dd9'); + $this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT fk_165051f6114b8dd9 FOREIGN KEY (linkedtothirdparty_id) REFERENCES chill_3party.third_party (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } +}