From 1e8d5e1eaf4267062eac86451aac13d2e04c618c Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 4 Aug 2025 10:56:53 +0200 Subject: [PATCH] Ajout organistion Id au Actions --- migrations/Version20250804084150.php | 36 ++++++++++++++++++++++++++++ migrations/Version20250804085615.php | 34 ++++++++++++++++++++++++++ src/Entity/Actions.php | 17 ++++++++++++- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20250804084150.php create mode 100644 migrations/Version20250804085615.php diff --git a/migrations/Version20250804084150.php b/migrations/Version20250804084150.php new file mode 100644 index 0000000..b4f1a09 --- /dev/null +++ b/migrations/Version20250804084150.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE actions ADD organization_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE actions ADD CONSTRAINT FK_548F1EF32C8A3DE FOREIGN KEY (organization_id) REFERENCES organizations (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_548F1EF32C8A3DE ON actions (organization_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE actions DROP CONSTRAINT FK_548F1EF32C8A3DE'); + $this->addSql('DROP INDEX IDX_548F1EF32C8A3DE'); + $this->addSql('ALTER TABLE actions DROP organization_id'); + } +} diff --git a/migrations/Version20250804085615.php b/migrations/Version20250804085615.php new file mode 100644 index 0000000..af4b79c --- /dev/null +++ b/migrations/Version20250804085615.php @@ -0,0 +1,34 @@ +addSql('DROP INDEX uniq_548f1ef67b3b43d'); + $this->addSql('CREATE INDEX IDX_548F1EF67B3B43D ON actions (users_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP INDEX IDX_548F1EF67B3B43D'); + $this->addSql('CREATE UNIQUE INDEX uniq_548f1ef67b3b43d ON actions (users_id)'); + } +} diff --git a/src/Entity/Actions.php b/src/Entity/Actions.php index 7beb41f..aa39be4 100644 --- a/src/Entity/Actions.php +++ b/src/Entity/Actions.php @@ -13,7 +13,7 @@ class Actions #[ORM\Column] private ?int $id = null; - #[ORM\OneToOne(cascade: ['persist', 'remove'])] + #[ORM\ManyToOne(cascade: ['persist', 'remove'])] private ?user $users = null; #[ORM\Column(length: 255)] @@ -22,6 +22,9 @@ class Actions #[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])] private ?\DateTimeImmutable $date = null; + #[ORM\ManyToOne(inversedBy: 'actions')] + private ?Organizations $Organization = null; + public function getId(): ?int { return $this->id; @@ -62,4 +65,16 @@ class Actions return $this; } + + public function getOrganization(): ?Organizations + { + return $this->Organization; + } + + public function setOrganization(?Organizations $Organization): static + { + $this->Organization = $Organization; + + return $this; + } }