diff --git a/src/Entity/ItemExtra.php b/src/Entity/ItemExtra.php new file mode 100644 index 0000000..4aec202 --- /dev/null +++ b/src/Entity/ItemExtra.php @@ -0,0 +1,60 @@ +id = new Ulid; + } + + public function getId(): Ulid + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getMenuItem(): ?MenuItem + { + return $this->menuItem; + } + + public function setMenuItem(?MenuItem $menuItem): static + { + $this->menuItem = $menuItem; + + return $this; + } +} diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php index 45e166f..9d301b3 100644 --- a/src/Entity/MenuItem.php +++ b/src/Entity/MenuItem.php @@ -100,4 +100,34 @@ class MenuItem return $this; } + + /** + * @return Collection + */ + public function getItemExtras(): Collection + { + return $this->itemExtras; + } + + public function addItemExtra(ItemExtra $itemExtra): static + { + if (!$this->itemExtras->contains($itemExtra)) { + $this->itemExtras->add($itemExtra); + $itemExtra->setMenuItem($this); + } + + return $this; + } + + public function removeItemExtra(ItemExtra $itemExtra): static + { + if ($this->itemExtras->removeElement($itemExtra)) { + // set the owning side to null (unless already changed) + if ($itemExtra->getMenuItem() === $this) { + $itemExtra->setMenuItem(null); + } + } + + return $this; + } } diff --git a/src/Entity/OrderItem.php b/src/Entity/OrderItem.php index 9d74a7a..b0c4f2b 100644 --- a/src/Entity/OrderItem.php +++ b/src/Entity/OrderItem.php @@ -27,9 +27,6 @@ class OrderItem #[ORM\JoinColumn(nullable: false)] private ?MenuItem $menuItem = null; - #[ORM\OneToMany(mappedBy: 'orderItem', targetEntity: ItemExtra::class)] - private Collection $extras; - public function __construct() { $this->id = new Ulid; diff --git a/src/Repository/ItemExtraRepository.php b/src/Repository/ItemExtraRepository.php new file mode 100644 index 0000000..2dd61d7 --- /dev/null +++ b/src/Repository/ItemExtraRepository.php @@ -0,0 +1,48 @@ + + * + * @method ItemExtra|null find($id, $lockMode = null, $lockVersion = null) + * @method ItemExtra|null findOneBy(array $criteria, array $orderBy = null) + * @method ItemExtra[] findAll() + * @method ItemExtra[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class ItemExtraRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ItemExtra::class); + } + +// /** +// * @return ItemExtra[] Returns an array of ItemExtra objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('i.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?ItemExtra +// { +// return $this->createQueryBuilder('i') +// ->andWhere('i.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}