nineskeletor/src/Entity/Tag.php

75 lines
1.4 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Tag.
*
* @ORM\Table(name="tag")
* @ORM\Entity(repositoryClass="App\Repository\TagRepository")
* @UniqueEntity("id", message="Ce nom de tag existe dèja")
*/
class Tag
{
/**
* @ORM\Id
* @ORM\Column(type="string")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="Child", mappedBy="tags")
*/
protected $childs;
public function __construct()
{
$this->childs = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
/**
* @return Collection|Child[]
*/
public function getChilds(): Collection
{
return $this->childs;
}
public function addChild(Child $child): self
{
if (!$this->childs->contains($child)) {
$this->childs[] = $child;
$child->addTag($this);
}
return $this;
}
public function removeChild(Child $child): self
{
if ($this->childs->contains($child)) {
$this->childs->removeElement($child);
$child->removeTag($this);
}
return $this;
}
}