Skip to content
Snippets Groups Projects
Commit 4e31f70b authored by PEREZ-RAMIREZ Julian's avatar PEREZ-RAMIREZ Julian
Browse files

creting v2 of db scheme

parent 788d980d
Branches
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250223162147 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE wishlist_item (wish_list_id INT NOT NULL, item_id INT NOT NULL, INDEX IDX_6424F4E8D69F3311 (wish_list_id), INDEX IDX_6424F4E8126F525E (item_id), PRIMARY KEY(wish_list_id, item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE wishlist_item ADD CONSTRAINT FK_6424F4E8D69F3311 FOREIGN KEY (wish_list_id) REFERENCES wish_list (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE wishlist_item ADD CONSTRAINT FK_6424F4E8126F525E FOREIGN KEY (item_id) REFERENCES item (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 wishlist_item DROP FOREIGN KEY FK_6424F4E8D69F3311');
$this->addSql('ALTER TABLE wishlist_item DROP FOREIGN KEY FK_6424F4E8126F525E');
$this->addSql('DROP TABLE wishlist_item');
}
}
......@@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\WishListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
......@@ -21,6 +23,10 @@ class WishList
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Item::class)]
#[ORM\JoinTable(name: "wishlist_item")]
private Collection $items;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $expiration_date = null;
......@@ -30,6 +36,11 @@ class WishList
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
public function __construct()
{
$this->items = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
......@@ -94,4 +105,28 @@ class WishList
return $this;
}
/**
* @return Collection<int, Item>
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Item $item): static
{
if (!$this->items->contains($item)) {
$this->items->add($item);
}
return $this;
}
public function removeItem(Item $item): static
{
$this->items->removeElement($item);
return $this;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment