src/Entity/FoodCategory.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\FoodItem;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\FoodCategoryRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. #[ORM\Entity(repositoryClassFoodCategoryRepository::class)]
  9. class FoodCategory
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private ?int $id null;
  15.     #[ORM\Column(type'string'length255)]
  16.     private ?string $name null;
  17.     #[ORM\Column(type'integer')]
  18.     private ?int $orderId null;
  19.     // OneToMany relationship with FoodItem
  20.     #[ORM\OneToMany(mappedBy'category'targetEntityFoodItem::class)]
  21.     private Collection $foodItems;
  22.     public function __construct()
  23.     {
  24.         $this->foodItems = new ArrayCollection();
  25.     }
  26.     public function __toString()
  27.     {
  28.         return $this->name;
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getOrderId(): ?int
  44.     {
  45.         return $this->orderId;
  46.     }
  47.     public function setOrderId(int $orderId): self
  48.     {
  49.         $this->orderId $orderId;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return Collection|FoodItem[]
  54.      */
  55.     public function getFoodItems(): Collection
  56.     {
  57.         return $this->foodItems;
  58.     }
  59.     public function addFoodItem(FoodItem $foodItem): self
  60.     {
  61.         if (!$this->foodItems->contains($foodItem)) {
  62.             $this->foodItems[] = $foodItem;
  63.             $foodItem->setCategory($this);
  64.         }
  65.         return $this;
  66.     }
  67.     public function removeFoodItem(FoodItem $foodItem): self
  68.     {
  69.         if ($this->foodItems->removeElement($foodItem)) {
  70.             // set the owning side to null (unless already changed)
  71.             if ($foodItem->getCategory() === $this) {
  72.                 $foodItem->setCategory(null);
  73.             }
  74.         }
  75.         return $this;
  76.     }
  77. }