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
+42
View File
@@ -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;
}
}