feat: update database relation

This commit is contained in:
Maël Gangloff
2024-07-11 22:20:20 +02:00
parent bad27c7b42
commit 6aad09297f
11 changed files with 146 additions and 83 deletions

View File

@@ -28,9 +28,16 @@ class Nameserver
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
private array $status = [];
/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')]
private Collection $domains;
public function __construct()
{
$this->nameserverEntities = new ArrayCollection();
$this->domains = new ArrayCollection();
}
public function getHandle(): ?string
@@ -102,4 +109,31 @@ class Nameserver
return $this;
}
/**
* @return Collection<int, Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
$domain->addNameserver($this);
}
return $this;
}
public function removeDomain(Domain $domain): static
{
if ($this->domains->removeElement($domain)) {
$domain->removeNameserver($this);
}
return $this;
}
}