diff --git a/migrations/Version20250214083512.php b/migrations/Version20250214083512.php new file mode 100644 index 0000000..67606f2 --- /dev/null +++ b/migrations/Version20250214083512.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A119EB6921'); + $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A119EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A119EB6921'); + $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A119EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); + } +} diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 6b2bb4a..b49aacd 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -15,8 +15,6 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; #[UniqueEntity(fields: ['mac'], message: 'This MAC address is already in use.')] class Client extends AbstractEntity { - - // TODO nueva variable bool isTeacher use NameableTrait; #[ORM\Column(length: 255, nullable: true)] diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index 08bcc81..97c3588 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; class Trace extends AbstractEntity { #[ORM\ManyToOne(inversedBy: 'traces')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] private ?Client $client = null; #[ORM\Column(length: 255, nullable: true)]