src/Entity/Model.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ModelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. #[ORM\Entity(repositoryClassModelRepository::class)]
  9. #[UniqueEntity(fields: ['model_name'], message'Il existe déjà un modèle avec ce nom.')]
  10. class Model
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255uniquetrue)]
  17.     private ?string $model_name null;
  18.     #[ORM\OneToMany(mappedBy'product_model'targetEntityProduct::class)]
  19.     private Collection $products;
  20.     #[ORM\ManyToOne(inversedBy'models')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?Brand $model_brand null;
  23.     public function __construct()
  24.     {
  25.         $this->products = new ArrayCollection();
  26.     }
  27.     public function getId(): ?int
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getModelName(): ?string
  32.     {
  33.         return $this->model_name;
  34.     }
  35.     public function setModelName(string $model_name): self
  36.     {
  37.         $this->model_name $model_name;
  38.         return $this;
  39.     }
  40.     /**
  41.      * @return Collection<int, Product>
  42.      */
  43.     public function getProducts(): Collection
  44.     {
  45.         return $this->products;
  46.     }
  47.     public function addProduct(Product $product): self
  48.     {
  49.         if (!$this->products->contains($product)) {
  50.             $this->products->add($product);
  51.             $product->setProductModel($this);
  52.         }
  53.         return $this;
  54.     }
  55.     public function removeProduct(Product $product): self
  56.     {
  57.         if ($this->products->removeElement($product)) {
  58.             // set the owning side to null (unless already changed)
  59.             if ($product->getProductModel() === $this) {
  60.                 $product->setProductModel(null);
  61.             }
  62.         }
  63.         return $this;
  64.     }
  65.     public function getModelBrand(): ?Brand
  66.     {
  67.         return $this->model_brand;
  68.     }
  69.     public function setModelBrand(?Brand $model_brand): self
  70.     {
  71.         $this->model_brand $model_brand;
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return $this->model_name;
  77.     }
  78. }