<?php
namespace App\Entity;
use App\Service\Helper\DateTimeHelper;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AnalogRepository")
* @ORM\Table(name="products__analogs" )
*/
class Analog
{
use IdTrait;
/**
* @ORM\Column(name="enabled", type="boolean", nullable=false, options={"default":1})
*/
private bool $enabled = true;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="analogs")
* @ORM\JoinColumn(name="owner_product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private Product $owner;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product")
* @ORM\JoinColumn(name="analog_product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private Product $product;
public function __construct(Product $owner, Product $analog)
{
if($owner === $analog) {
throw new \Exception('Запчасть не может быть своим же оригиналом');
}
$this->owner = $owner;
$this->product = $analog;
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function getOwner(): Product
{
return $this->owner;
}
public function getProduct(): Product
{
return $this->product;
}
}