You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.0 KiB
90 lines
2.0 KiB
<?php
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping\Entity;
|
|
use Doctrine\ORM\Mapping\JoinColumn;
|
|
use Doctrine\ORM\Mapping\ManyToOne;
|
|
use Doctrine\ORM\Mapping\OneToMany;
|
|
use Doctrine\ORM\Mapping\OneToOne;
|
|
|
|
#[Entity]
|
|
class Prefecture extends Thing
|
|
{
|
|
|
|
#[OneToOne()]
|
|
#[JoinColumn(onDelete: 'cascade', nullable: false)]
|
|
public City $capital;
|
|
|
|
#[ManyToOne()]
|
|
#[JoinColumn(onDelete: 'cascade', nullable: false)]
|
|
public Country $country;
|
|
|
|
/** @var Village[] */
|
|
#[OneToMany(targetEntity: Village::class, mappedBy: 'prefecture')]
|
|
#[JoinColumn(onDelete: 'cascade', nullable: false)]
|
|
public iterable $villages;
|
|
|
|
// FIXME:Shortcut to its users?
|
|
public function __construct()
|
|
{
|
|
$this->villages = new ArrayCollection();
|
|
}
|
|
|
|
public function getCapital(): ?City
|
|
{
|
|
return $this->capital;
|
|
}
|
|
|
|
public function setCapital(City $capital): static
|
|
{
|
|
$this->capital = $capital;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCountry(): ?Country
|
|
{
|
|
return $this->country;
|
|
}
|
|
|
|
public function setCountry(?Country $country): static
|
|
{
|
|
$this->country = $country;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Village>
|
|
*/
|
|
public function getVillages(): Collection
|
|
{
|
|
return $this->villages;
|
|
}
|
|
|
|
public function addVillage(Village $village): static
|
|
{
|
|
if (!$this->villages->contains($village)) {
|
|
$this->villages->add($village);
|
|
$village->setPrefecture($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeVillage(Village $village): static
|
|
{
|
|
if ($this->villages->removeElement($village)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($village->getPrefecture() === $this) {
|
|
$village->setPrefecture(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|
|
|