<?php
namespace App\Entity;
use App\Repository\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TagRepository::class)]
class Tag
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Node::class, mappedBy: 'tags')]
private $nodes;
public function __construct()
{
$this->nodes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Node>
*/
public function getNodes(): Collection
{
return $this->nodes;
}
public function addNode(Node $node): static
{
if (!$this->nodes->contains($node)) {
$this->nodes->add($node);
$node->addTag($this);
}
return $this;
}
public function removeNode(Node $node): static
{
if ($this->nodes->removeElement($node)) {
$node->removeTag($this);
}
return $this;
}
}