<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Instrument::class, orphanRemoval: true)]
private Collection $instruments;
public function __construct()
{
$this->instruments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Instrument>
*/
public function getInstruments(): Collection
{
return $this->instruments;
}
public function addInstrument(Instrument $instrument): self
{
if (!$this->instruments->contains($instrument)) {
$this->instruments->add($instrument);
$instrument->setCategory($this);
}
return $this;
}
public function removeInstrument(Instrument $instrument): self
{
if ($this->instruments->removeElement($instrument)) {
// set the owning side to null (unless already changed)
if ($instrument->getCategory() === $this) {
$instrument->setCategory(null);
}
}
return $this;
}
}