diff --git a/src/Entity/Gallery.php b/src/Entity/Gallery.php index 05dd42a60893121c51ccbb0829d547218ab3abad..7f1c5f36d744a7370f725e7ef8e4781f77285dd7 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; }