src/Entity/County.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CountyRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CountyRepository::class)
  9.  */
  10. class County
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column
  16.      */
  17.     private ?int $id null;
  18.     /**
  19.      * @ORM\Column(length=255)
  20.      */
  21.     private ?string $name null;
  22.     /**
  23.      * @ORM\Column(length=255)
  24.      */
  25.     private ?string $ctyCode null;
  26.     /**
  27.      * @ORM\OneToMany(mappedBy="county", targetEntity=City::class)
  28.      */
  29.     private Collection $cities;
  30.     public function __construct()
  31.     {
  32.         $this->cities = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getName(): ?string
  39.     {
  40.         return $this->name;
  41.     }
  42.     public function setName(string $name): static
  43.     {
  44.         $this->name $name;
  45.         return $this;
  46.     }
  47.     public function getCtyCode(): ?string
  48.     {
  49.         return $this->ctyCode;
  50.     }
  51.     public function setCtyCode(string $ctyCode): static
  52.     {
  53.         $this->ctyCode $ctyCode;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection<int, City>
  58.      */
  59.     public function getCities(): Collection
  60.     {
  61.         return $this->cities;
  62.     }
  63.     public function addCity(City $city): static
  64.     {
  65.         if (!$this->cities->contains($city)) {
  66.             $this->cities->add($city);
  67.             $city->setCounty($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeCity(City $city): static
  72.     {
  73.         if ($this->cities->removeElement($city)) {
  74.             // set the owning side to null (unless already changed)
  75.             if ($city->getCounty() === $this) {
  76.                 $city->setCounty(null);
  77.             }
  78.         }
  79.         return $this;
  80.     }
  81. }