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\BuildingRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@@ -23,6 +25,16 @@ class Building
|
||||
*/
|
||||
private $site;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=Floor::class, mappedBy="building")
|
||||
*/
|
||||
private $floors;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->floors = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -39,4 +51,34 @@ class Building
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Floor>
|
||||
*/
|
||||
public function getFloors(): Collection
|
||||
{
|
||||
return $this->floors;
|
||||
}
|
||||
|
||||
public function addFloor(Floor $floor): self
|
||||
{
|
||||
if (!$this->floors->contains($floor)) {
|
||||
$this->floors[] = $floor;
|
||||
$floor->setBuilding($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeFloor(Floor $floor): self
|
||||
{
|
||||
if ($this->floors->removeElement($floor)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($floor->getBuilding() === $this) {
|
||||
$floor->setBuilding(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user