Skip to content

Instantly share code, notes, and snippets.

@evgeniy123
Created March 31, 2024 21:01
Show Gist options
  • Select an option

  • Save evgeniy123/b28cb758aba881dae59e89cf9b34f4ef to your computer and use it in GitHub Desktop.

Select an option

Save evgeniy123/b28cb758aba881dae59e89cf9b34f4ef to your computer and use it in GitHub Desktop.
class DeliveryMethod implements AggregateRoot
{
use EventsTrait;
use PropertiesDateUpdateCreateTrait;
#[ORM\Column(type: "delivery_method_id")]
#[ORM\Id]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: false)]
private $name;
#[ORM\OneToMany(targetEntity: ShopMethodDelivery::class, mappedBy: 'deliveryMethod')]
private $shopMethodDelivery;
....
....
$shop_1->attachMethodDeliveryForShop($deliveryMethodEatIn);
....
#[ORM\Entity()]
#[ORM\Table(name: 'shop')]
#[Index(name: "shop_idx", columns: ["id"])]
class Shop implements AggregateRoot
{
#[ORM\Column(type: "shop_id")]
#[ORM\Id]
private $id;
#[ORM\ManyToMany(targetEntity: ShopMethodDelivery::class, mappedBy: 'shop', cascade: ['persist'], orphanRemoval: true)]
private Collection $shopMethodDelivery;
....
...
public function attachMethodDeliveryForShop(DeliveryMethod $deliveryMethod): static
{
if (!$this->shopMethodDelivery->contains($deliveryMethod)) {
$this->shopMethodDelivery->add($deliveryMethod);
$deliveryMethod->setShop($this);
}
return $this;
}
....
class ShopMethodDelivery implements AggregateRoot
{
#[ORM\Column(type: "shop_method_delivery_id")]
#[ORM\Id]
private $id;
#[ORM\ManyToMany(targetEntity: Shop::class, inversedBy: 'shopMethodDelivery')]
private $shop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment