<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use App\Entity\Category;
use App\Entity\Product;
use App\Entity\ProductModel;
/**
* ProductsToCategories
*
* @ORM\Table(name="products_to_categories", indexes={@ORM\Index(name="idx_categories_id", columns={"categories_id", "products_id"})})
* @ORM\Entity(repositoryClass="App\Repository\CategoryProductRepository")
* @ORM\HasLifecycleCallbacks()
*/
class CategoryProduct {
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var ?Product
*
*
*
* @ORM\ManyToOne(targetEntity="App\Entity\Product")
* @ORM\JoinColumn(name="products_id", referencedColumnName="products_id", onDelete="cascade")
*/
private $product;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="App\Entity\Category")
* @ORM\JoinColumn(name="categories_id", referencedColumnName="categories_id", onDelete="cascade")
*/
private $category;
public function getId() {
return $this->id;
}
public function getProduct() {
return $this->product;
}
public function getModel(): ?ProductModel {
return $this->model;
}
public function getCategory() {
return $this->category;
}
public function setProduct(Product $product) {
$this->product = $product;
}
public function setCategory(Category $category) {
$this->category = $category;
}
public function setModel(?ProductModel $model): void {
$this->model = $model;
}
/**
* @ORM\PostLoad
*
* @todo Remove once 0 values in the table are converted to NULL.
*/
public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
if ($this->product && $this->product->getId() == 0) {
$this->product = null;
}
if ($this->category && $this->category->getId() == 0) {
$this->category = null;
}
}
}