From 1470e5cbe419f63a028f4f32898405abae09a267 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Thu, 2 May 2024 13:43:06 +0500 Subject: [PATCH] =?UTF-8?q?STA-965=20|=20=D0=9F=D0=BE=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20Gallery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/Gallery.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Entity/Gallery.php b/src/Entity/Gallery.php index 05dd42a..7f1c5f3 100644 --- a/src/Entity/Gallery.php +++ b/src/Entity/Gallery.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\GalleryRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Uid\Uuid; @@ -14,39 +16,43 @@ class Gallery #[ORM\Column(type: 'uuid', unique: true)] private ?Uuid $id = null; - #[ORM\ManyToOne(inversedBy: 'galleries')] - #[ORM\JoinColumn(nullable: false)] - private ?Restaurant $restaurant = null; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: File::class)] + private Collection $files; + + public function __construct() + { + $this->files = new ArrayCollection(); + } - #[ORM\OneToOne(cascade: ['persist', 'remove'])] - #[ORM\JoinColumn(nullable: false)] - private ?File $file = null; - public function getId(): ?int + public function getId(): ?Uuid { return $this->id; } - public function getRestaurant(): ?Restaurant + /** + * @return Collection + */ + public function getFile(): Collection { - return $this->restaurant; + return $this->files; } - public function setRestaurant(?Restaurant $restaurant): static + public function addFile(File $file): static { - $this->restaurant = $restaurant; + if (!$this->files->contains($file)) { + $this->files->add($file); + } return $this; } - public function getFile(): ?File - { - return $this->file; - } - - public function setFile(File $file): static + public function removeFile(File $file): static { - $this->file = $file; + $this->files->removeElement($file); return $this; } -- GitLab