Ajout des relations OtM et MtM

This commit is contained in:
2022-11-16 15:24:07 +01:00
parent 87c1d313fb
commit 3e9cae5270
4 changed files with 189 additions and 0 deletions
+69
View File
@@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\PlaceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -17,8 +19,75 @@ class Place
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity=Place::class, inversedBy="connectedPlaces")
*/
private $connection;
/**
* @ORM\ManyToMany(targetEntity=Place::class, mappedBy="connection")
*/
private $connectedPlaces;
public function __construct()
{
$this->connection = new ArrayCollection();
$this->connectedPlaces = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, self>
*/
public function getConnection(): Collection
{
return $this->connection;
}
public function addConnection(self $connection): self
{
if (!$this->connection->contains($connection)) {
$this->connection[] = $connection;
}
return $this;
}
public function removeConnection(self $connection): self
{
$this->connection->removeElement($connection);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getConnectedPlaces(): Collection
{
return $this->connectedPlaces;
}
public function addConnectedPlace(self $connectedPlace): self
{
if (!$this->connectedPlaces->contains($connectedPlace)) {
$this->connectedPlaces[] = $connectedPlace;
$connectedPlace->addConnection($this);
}
return $this;
}
public function removeConnectedPlace(self $connectedPlace): self
{
if ($this->connectedPlaces->removeElement($connectedPlace)) {
$connectedPlace->removeConnection($this);
}
return $this;
}
}