entityManager = $entityManager; $this->orderShopStore = $orderShopStore; $this->documentStore = $documentStore; } // unlinkAddress public function unlink(Address $address): void { $orderShops = $this->orderShopStore->getBy( [ 'address' => $address ] ); if ($orderShops) { foreach ($orderShops as $orderShop) { $update = false; if ($orderShop->getInvoiceAddress() == $address) { $orderShop->setInvoiceAddress(null); $update = true; } if ($orderShop->getDeliveryAddress() == $address) { $orderShop->setDeliveryAddress(null); $update = true; } if ($update) { $this->entityManager->update($orderShop); } } } $documents = $this->documentStore->getByBuyerAddress($address); if ($documents) { foreach ($documents as $document) { $update = false; if ($document->getBuyerAddress() == $address) { $document->setBuyerAddress(null); $update = true; } if ($update) { $this->entityManager->update($document); } } } $this->entityManager->flush(); } }