<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_product_subcategory")
* @ORM\Entity(repositoryClass="App\Repository\Slave\ProductSubcategoryRepository")
*/
class ProductSubcategory
{
public function __toString(){
return $this->getName();
}
public function getCanDelete(){
if(sizeof($this->models) > 0) return false;
return true;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=191)
*/
protected $name;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\ProductCategory", inversedBy="subcategories")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
private $category;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductModel", mappedBy="subcategory")
*/
private $models;
//
public function __construct()
{
$this->models = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCategory(): ?ProductCategory
{
return $this->category;
}
public function setCategory(?ProductCategory $category): self
{
$this->category = $category;
return $this;
}
/**
* @return Collection<int, ProductModel>
*/
public function getModels(): Collection
{
return $this->models;
}
public function addModel(ProductModel $model): self
{
if (!$this->models->contains($model)) {
$this->models->add($model);
$model->setSubcategory($this);
}
return $this;
}
public function removeModel(ProductModel $model): self
{
if ($this->models->removeElement($model)) {
// set the owning side to null (unless already changed)
if ($model->getSubcategory() === $this) {
$model->setSubcategory(null);
}
}
return $this;
}
}