<?phpnamespace App\Entity;use App\Repository\SubdivisionRepository;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass=SubdivisionRepository::class) * @ORM\HasLifecycleCallbacks() */class Subdivision{ /** * @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=City::class, inversedBy="subdivisions") * @ORM\JoinColumn(nullable=false) * @Assert\NotBlank */ private $city; /** * @ORM\OneToOne(targetEntity=Municipality::class, mappedBy="subdivision", cascade={"persist", "remove"}) * @ORM\JoinColumn(nullable=true) */ private $municipality; public function __construct() { $this->setUpdateAt(new \DateTime()); } 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 getCity(): ?City { return $this->city; } public function setCity(?City $city): self { $this->city = $city; return $this; } /** * @ORM\PreUpdate */ public function __updateDate() { $this->setUpdateAt(new \DateTime()); } public function getMunicipality(): ?Municipality { return $this->municipality; } public function setMunicipality(Municipality $municipality): self { $this->municipality = $municipality; // set the owning side of the relation if necessary if ($municipality->getSubdivision() !== $this) { $municipality->setSubdivision($this); } return $this; } public function __toString() { return $this->getName(); }}