<?php
namespace App\Entity;
use App\Repository\DistrictRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DistrictRepository::class)
*/
class District
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $districtName;
/**
* @ORM\OneToMany(targetEntity=Department::class, mappedBy="district")
*/
private $departments;
public function __construct()
{
$this->departments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDistrictName(): ?string
{
return $this->districtName;
}
public function setDistrictName(string $districtName): self
{
$this->districtName = $districtName;
return $this;
}
/**
* @return Collection|Department[]
*/
public function getDepartments(): Collection
{
return $this->departments;
}
public function addDepartment(Department $department): self
{
if (!$this->departments->contains($department)) {
$this->departments[] = $department;
$department->setDistrict($this);
}
return $this;
}
public function removeDepartment(Department $department): self
{
if ($this->departments->contains($department)) {
$this->departments->removeElement($department);
// set the owning side to null (unless already changed)
if ($department->getDistrict() === $this) {
$department->setDistrict(null);
}
}
return $this;
}
public function __toString(){
return $this->districtName;
}
}