src/Entity/Region.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RegionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassRegionRepository::class)]
  8. #[ORM\Table(name'region')]
  9. class Region
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(targetEntityCountry::class, inversedBy'regions')]
  16.     #[ORM\JoinColumn(name'country_id'referencedColumnName'id'nullablefalse)]
  17.     private ?Country $country null;
  18.     #[ORM\Column(length100)]
  19.     private ?string $name null;
  20.     #[ORM\Column(length50)]
  21.     private ?string $code null;
  22.     /** @var Collection<int, City> */
  23.     #[ORM\OneToMany(mappedBy'region'targetEntityCity::class, cascade: ['persist'])]
  24.     private Collection $cities;
  25.     public function __construct()
  26.     {
  27.         $this->cities = new ArrayCollection();
  28.     }
  29.     public function getId(): ?int { return $this->id; }
  30.     public function getCountry(): ?Country { return $this->country; }
  31.     public function setCountry(?Country $country): self $this->country $country; return $this; }
  32.     public function getName(): ?string { return $this->name; }
  33.     public function setName(string $name): self $this->name $name; return $this; }
  34.     public function getCode(): ?string { return $this->code; }
  35.     public function setCode(string $code): self $this->code $code; return $this; }
  36.     /** @return Collection<int, City> */
  37.     public function getCities(): Collection { return $this->cities; }
  38.     public function addCity(City $city): self
  39.     {
  40.         if (!$this->cities->contains($city)) {
  41.             $this->cities->add($city);
  42.             $city->setRegion($this);
  43.         }
  44.         return $this;
  45.     }
  46.     public function removeCity(City $city): self
  47.     {
  48.         if ($this->cities->removeElement($city)) {
  49.             if ($city->getRegion() === $this) {
  50.                 $city->setRegion(null);
  51.             }
  52.         }
  53.         return $this;
  54.     }
  55.     public function __toString(): string { return $this->name ?? ''; }
  56. }