<?phpnamespace App\Entity;use App\Repository\DepartmentRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass=DepartmentRepository::class) * @ORM\HasLifecycleCallbacks() */class Department{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\Column(type="text", nullable=true) */ private $description; /** * @ORM\Column(type="datetime", nullable=true) */ private $updateAt; /** * @ORM\ManyToOne(targetEntity=Region::class, inversedBy="departments") * @ORM\JoinColumn(nullable=false) */ private $region; /** * @ORM\OneToMany(targetEntity=City::class, mappedBy="department", orphanRemoval=true) */ private $cities; public function __construct() { $this->cities = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(?string $description): self { $this->description = $description; return $this; } public function getUpdateAt(): ?\DateTimeInterface { return $this->updateAt; } public function setUpdateAt(?\DateTimeInterface $updateAt): self { $this->updateAt = $updateAt; return $this; } public function getRegion(): ?Region { return $this->region; } public function setRegion(?Region $region): self { $this->region = $region; return $this; } /** * @return Collection|City[] */ public function getCities(): Collection { return $this->cities; } public function addCity(City $city): self { if (!$this->cities->contains($city)) { $this->cities[] = $city; $city->setDepartment($this); } return $this; } public function removeCity(City $city): self { if ($this->cities->contains($city)) { $this->cities->removeElement($city); // set the owning side to null (unless already changed) if ($city->getDepartment() === $this) { $city->setDepartment(null); } } return $this; } public function __toString() { return $this->getName(); } /** * @ORM\PreUpdate */ public function __updateDate() { $this->setUpdateAt(new \DateTime()); }}