src/Entity/Serie.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\Entity;
  4. use App\Repository\SerieRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassSerieRepository::class)]
  10. class Serie extends Entity
  11. {
  12.     #[ORM\Column(length255)]
  13.     #[Groups(['product:read'])]
  14.     private ?string $name null;
  15.     #[ORM\ManyToOne(inversedBy'series')]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private ?Family $family null;
  18.     #[ORM\OneToMany(mappedBy'serie'targetEntityProduct::class)]
  19.     private Collection $products;
  20.     public function __construct(string $name nullFamily $family null)
  21.     {
  22.         $this->name $name;
  23.         $this->family $family;
  24.         $this->products = new ArrayCollection();
  25.     }
  26.     public function getName(): ?string
  27.     {
  28.         return $this->name;
  29.     }
  30.     public function setName(string $name): self
  31.     {
  32.         $this->name $name;
  33.         return $this;
  34.     }
  35.     public function getFamily(): ?Family
  36.     {
  37.         return $this->family;
  38.     }
  39.     public function setFamily(?Family $family): self
  40.     {
  41.         $this->family $family;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return Collection<int, Product>
  46.      */
  47.     public function getProducts(): Collection
  48.     {
  49.         return $this->products;
  50.     }
  51.     public function addProduct(Product $product): self
  52.     {
  53.         if (!$this->products->contains($product)) {
  54.             $this->products->add($product);
  55.             $product->setSerie($this);
  56.         }
  57.         return $this;
  58.     }
  59.     public function removeProduct(Product $product): self
  60.     {
  61.         if ($this->products->removeElement($product)) {
  62.             // set the owning side to null (unless already changed)
  63.             if ($product->getSerie() === $this) {
  64.                 $product->setSerie(null);
  65.             }
  66.         }
  67.         return $this;
  68.     }
  69.     public function __toString(): string
  70.     {
  71.         return $this->name;
  72.     }
  73. }