63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\{ArrayCollection, Collection};
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Stringable;
|
|
|
|
#[ORM\Table(name: 'brand', schema: 'collection')]
|
|
#[ORM\Entity]
|
|
#[ORM\UniqueConstraint(name: 'brand_unq', columns: ['name'])]
|
|
class Brand implements Stringable {
|
|
use GetSet;
|
|
|
|
#[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)]
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
|
|
#[ORM\SequenceGenerator(sequenceName: 'brand_id_seq', allocationSize: 1, initialValue: 1)]
|
|
private int $id;
|
|
|
|
/**
|
|
* @var Collection<int, BrandCategory>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: BrandCategory::class, fetch: 'EXTRA_LAZY')]
|
|
#[ORM\JoinTable(name: 'collection.brand_category_link')]
|
|
#[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id')]
|
|
#[ORM\InverseJoinColumn(name: 'brand_category', referencedColumnName: 'category_name')]
|
|
#[ORM\OrderBy(['name' => 'asc'])]
|
|
private Collection $categories;
|
|
|
|
#[ORM\Column(name: 'name', unique: TRUE, nullable: FALSE)]
|
|
private string $name;
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
public function __construct()
|
|
{
|
|
$this->categories = new ArrayCollection();
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function addCategory(BrandCategory $category): self
|
|
{
|
|
if ( ! $this->categories->contains($category))
|
|
{
|
|
$this->categories->add($category);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeCategory(BrandCategory $category): self
|
|
{
|
|
$this->categories->removeElement($category);
|
|
|
|
return $this;
|
|
}
|
|
}
|