Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Entity;
- use App\Repository\ProductRepository;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * @ORM\Entity(repositoryClass=ProductRepository::class)
- */
- class Product
- {
- /**
- * @ORM\Id
- * @ORM\GeneratedValue
- * @ORM\Column(type="integer")
- */
- private $id;
- /**
- * @ORM\Column(type="string", length=100)
- */
- private $name;
- /**
- * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="product")
- */
- private $Category;
- public function __construct()
- {
- $this->Category = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getName(): ?string
- {
- return $this->name;
- }
- public function setName(string $name): self
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @return Collection<int, Category>
- */
- public function getCategory(): Collection
- {
- return $this->Category;
- }
- public function addCategory(Category $category): self
- {
- if (!$this->Category->contains($category)) {
- $this->Category[] = $category;
- $category->addProduct($this);
- }
- return $this;
- }
- public function removeCategory(Category $category): self
- {
- if ($this->Category->removeElement($category)) {
- $category->removeProduct($this);
- }
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement