Removes existing relations

@param EntityInterface $entity
@param EntityCollectionInterface $collection

@return self
329049
protected function deleteRelation(
        EntityInterface $entity,
        EntityCollectionInterface $collection
    ) {
        $repository = $this->getParentRepository();
        $adapter = $repository->getAdapter();
        $parts = explode('\\', $this->getEntityDescriptor()->className());
        $entityName = lcfirst(array_pop($parts));
        $parts = explode('\\', $this->getParentEntityDescriptor()->className());
        $relatedName = lcfirst(array_pop($parts));
        $value = $collection->parentEntity()->getId();
        Sql::createSql($adapter)
            ->delete($this->getRelationTable())
            ->where(
                [
                    "{$this->getRelatedForeignKey()} = :{$relatedName} AND
                     {$this->getForeignKey()} = :{$entityName}" => [
                        ":{$relatedName}" => $entity->getId(),
                        ":{$entityName}" => $value
                    ]
                ]
            )
            ->execute();
        return $this;
    }
176628
protected function clearPreviousCollection(Collection $collection)
    {
        if ($collection->count()) {
            foreach ($collection as $item) {
                $collection->removeElement($item);
            }
        }
    }
510349
public function removeChildrenEntity(Entity $childrenEntity)
    {
        foreach ($this->childrenEntities as $key => $childrenEntityElement) {
            if ($childrenEntityElement === $childrenEntity) {
                unset($this->childrenEntities[$key]);
                break;
            }
        }

        return $this;
    }
1244964
public function remove(object $entity): self
    {
        $identity = $this->extractIdentity($entity);

        try {
            $state = $this->container->stateFor($identity);

            switch ($state) {
                case State::new():
                    $this->container->push(
                        $identity,
                        $entity,
                        State::removed()
                    );
                    break;

                case State::managed():
                    $this->container->push(
                        $identity,
                        $entity,
                        State::toBeRemoved()
                    );
                    break;
            }
        } catch (IdentityNotManaged $e) {
            //pass
        }

        return $this;
    }
443759
public function set($collectionId, EntityCollectionInterface $collection)
    {
        $this->getCache()->set($collectionId, $collection);
        return $this;
    }
1198575
protected function cleanup($entityName, array $collection, array $conditions)
    {
        if (!$existing = $this->isCleanupNecessary($entityName, $conditions)) {
            return;
        }

        $identifiers = [];
        foreach ($collection as $instance) {
            $identifiers[] = $this->identifyEntity($instance, $entityName);
        }

        foreach ($existing as $instance) {
            if (in_array($this->identifyEntity($instance, $entityName), $identifiers)) {
                continue;
            }

            $this->storage->delete($instance, $entityName)->execute();
        }

        return;
    }
1359596
public function remove($entity)
    {
        $objectManager = $this->getObjectManager();
        $objectManager->remove($entity);
        $objectManager->flush();
    }
530216
public function clear($entity)
    {
        /**
         * @var ObjectManager $objectManager
         */
        $objectManager = $this
            ->get('elcodi.provider.manager')
            ->getManagerByEntityNamespace(get_class($entity));

        $objectManager->clear($entity);

        return $this;
    }
260223
public function remove(ModelInterface $model): RepositoryInterface
    {
        $id = $model->getId();
        $table = $this->getTable();

        if (null === $this->find($id)) {
            return $this;
        }

        $this->connection->beginTransaction();

        $row = $model->toPersistence();

        foreach ($row as $field => $value) {
            if ($value instanceof ModelCollectionInterface) {
                $this->removeRelatedModels($value->getInitialModels());
            } elseif ($value instanceof ModelReferenceInterface) {
                if (null !== $initialModel = $value->getInitialModel()) {
                    $this->removeRelatedModel($initialModel);
                }
            }
        }

        $this->logger->info(
            'model: remove row from table {table} with id {id}',
            ['table' => $table, 'id' => $id]
        );

        $this->connection->delete($table, ['id' => $id]);

        $this->storageCache->remove($id);

        $this->connection->commit();

        return $this;
    }
478894
protected function deleteEntity($entity)
    {
        $this->checkEntityType($entity);

        $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder());

        $delete->execute();
    }
408861
public function deleteBatch(EntityInterface $entity)
    {
        if (is_null($this->deleteBatch)) {
            $this->deleteBatch = WriteRequestBatch::factory($this->dynamoDb);
        }
        $this->deleteBatch->add(new DeleteRequest($this->formatKeyCondition($entity), $this->getEntityTable($entity)));
    }
202655
public function remove(EntityRemoved $event)
    {
        $entity = $event->getEntity();
        $collection = $event->getCollection();
        $this->deleteRelation($entity, $collection);
    }
1079435
public function deleteEntity(SearchableEntityInterface $entity)
    {
        foreach ($this->locales as $locale) {
            $uid       = $this->getDocUid($entity, $locale);
            $indexType = $this->indexType;
            $this->searchProvider->deleteDocument($this->indexName, $indexType, $uid);
        }
    }
943330
@Override
  public <T> List<T> remove(Collection<? extends T> batchToRemove, Class<T> entityClass) {
    return remove(batchToRemove, Util.determineCollectionName(entityClass));
  }
812663
public function updateRelations($entity) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, get_class($entity));
        foreach ($mapper->getRelations() as $relation) {
            if ($relation->getCardinality() == Relation::$manyToMany) {
                // delete previous relations
                $queryDeletePrevious = $this->buildDeleteRelationQuery($relation, $entity);
                $this->conn->executeNonQuery($queryDeletePrevious);

                // insert new relations
                $queryRel = $this->buildRelationQuery($entity);
                foreach (explode(";", $queryRel) as $q) {
                    if (strlen($q) > 5)
                        $this->conn->executeInsert($q);
                }
            }
            if ($relation->getCardinality() == Relation::$oneToMany) {
                $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
                $m = "get" . $relation->getName();
                $setid = "set" . $relMapper->getNameForColumn($relation->getForeignColumn());

                // save actual relations
                foreach ($entity->$m() as $relEntity) {
                    $relEntity->$setid($entity->getId());
                    $this->save($relEntity);
                }

                //  delete old relations.
                // TODO: delete old relations
            }
        }
    }
1047850
public function removeEntity($entity)
    {
        $registries = $this->findRegistriesEntityById(get_class($entity), $entity->getObjectIdentifier());

        foreach ($registries as $registry) {
            $this->remove($registry);
        }
    }
576333
private function forgetCollection(Collection $collection)
    {
        $query_builder = $this->manager->createQueryBuilder();
        $query_builder
            ->delete(StackUsageRecord::class, 'r')
            ->where('r.collection_id = :collection_id')
            ->setParameter('collection_id', $collection->getCollectionID())
            ->getQuery()->execute();
    }