mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-09-11 16:50:46 +02:00
Ajout des relations OtM et MtM
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user