<?php
namespace App\Entity;
use App\Model\Entity;
use App\Repository\RangeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RangeRepository::class)]
#[ORM\Table(name: '`range`')]
class Range extends Entity
{
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'ranges')]
#[ORM\JoinColumn(nullable: false)]
private ?Family $family = null;
#[ORM\OneToMany(mappedBy: 'range', targetEntity: Product::class)]
private Collection $products;
public function __construct(string $name = null, Family $family = null)
{
$this->name = $name;
$this->family = $family;
$this->products = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getFamily(): ?Family
{
return $this->family;
}
public function setFamily(?Family $family): self
{
$this->family = $family;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setRange($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getRange() === $this) {
$product->setRange(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name . ' (' . $this->family . ')';
}
}