Deletes any many to many references pointing to the given entity.

@param Entity $entity
the referenced entity
501324
protected function deleteManyToManyReferences(Entity $entity)
    {
        foreach ($this->definition->getService()->getEntities() as $entityName) {
            $data = $this->definition->getService()->getData($entityName);
            foreach ($data->getDefinition()->getFieldNames(true) as $field) {
                if ($data->getDefinition()->getType($field) == 'many') {
                    $otherEntity = $data->getDefinition()->getSubTypeField($field, 'many', 'entity');
                    $otherData   = $this->definition->getService()->getData($otherEntity);
                    if ($entity->getDefinition()->getTable() == $otherData->getDefinition()->getTable()) {
                        $thatField    = $data->getDefinition()->getSubTypeField($field, 'many', 'thatField');
                        $queryBuilder = $this->database->createQueryBuilder();
                        $queryBuilder
                            ->delete('`'.$field.'`')
                            ->where('`'.$thatField.'` = ?')
                            ->setParameter(0, $entity->get('id'))
                            ->execute()
                        ;
                    }
                }
            }
        }
    }
642714
public function delete($id)
    {
        $this->beforeDelete($id);
        $this->entity->delete($id);
        $this->afterDelete($id);
    }
303490
public function destroy(Entity $entity)
    {
        $requiredClass = Convention::nameToClass($this->getEntityName(), Convention::ENTITY_MASK);
        if (!$entity instanceof $requiredClass) {
            throw new Exception\RepositoryException(
                "Entity must be instance of ". $requiredClass . "!"
            );
        }

        $reflection = $entity::getReflection();
        if (!$reflection->hasPrimary()) {
            throw new Exception\RepositoryException(
                "Can not delete entity without primary property!"
            );
        }

        $primaryName = $reflection->getPrimaryProperty()->getName();

        try {
            return $this->query()->deleteOne($entity->{$primaryName})->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
1199281
public function remove(AbstractEntity $entity)
    {
        if ($this->prepareEntityForRemove($entity)) {
            $this->getRepository()->remove($entity);
        }
    }
1046357
public function deleted(Model $entity)
    {
        $data = [
            'database' => $this->getConnectionName(),
            'driver' => $this->getDriverName(),
        ];

        $this->dispatch($this->getDeleteTenantJob($entity, $data));

        return true;
    }
99052
public function deleteEntityById($entity, $id)
    {
        $tbl = $this->_resource->getTableName($entity);
        $where = [];
        foreach ($id as $field => $value) {
            $where["`$field`=?"] = $value;
        }
        $result = $this->_conn->delete($tbl, $where);
        return $result;
    }
211909
public function delete(Record $record, Entity $entity)
    {
        (new DeleteRecord($record, $entity, $this))->execute();

        return $this;
    }
1297247
protected function _resetrelationships($entity)
    {
        $entities = clone $entity->getRepository()->getSpace()->getEntities();

        //reset all the entities that have a belongs to or one to one relationship
        //with the $entity. Because since $entity is not being saved
        //nor should any child that requires the parent $entity value 
        foreach ($entities as $child) {
            if ($child->eql($entity)) {
                continue;
            }

            $relationships = $child->getEntityDescription()->getRelationships();

            foreach ($relationships as $relationship) {
                //child has a one to one or belongs to relationship to the entity (parent) 
                if ($relationship->isOneToOne() || $relationship->isManyToOne()) {
                    $value = $child->get($relationship->getName());

                    if ($entity->eql($value)) {
                        $child->reset();
                    }
                }
            }
        }
    }
715776
public function delete($entity)
    {
        $this->gateway->delete($this->tableName, $this->builder->reduce($entity), $this->getIdentifier($entity));
    }
1139376
public function delete()
    {
        $keys = $this->getList();
        foreach ($keys as $key) {
            $this->entityManager->remove($key);
        }
        $this->entityManager->flush();
    }
602523
public boolean deleteEntity(Entity entity) {
        String entityName = entity.getName();
        checkEntityIsEmpty(entityName);
        QueryPart<Entity> queryPart = new Query<Entity>("entities")
                .path(entityName, true);
        return httpClientManager.updateMetaData(queryPart, delete());
    }
255254
@Override
	public void delete(Object entity) {
		if (entity == null) {
			throw new IllegalArgumentException("'entity' must not be [" + entity + "]");
		}
		
		if (operation != Log.Operation.GET) {
			throw new IllegalStateException("Log [" + operation + "] -> ["
					+ Log.Operation.DELETE
					+ "] is not allowed: previous operation must be ["
					+ Log.Operation.GET + "]");
		}
		
		operation = Log.Operation.DELETE;
	}
272947
public <T> void delete(T entity) {
        if (entity == null) {
            throw new IllegalArgumentException("Entity cannot be null");
        }

        DocumentInfo value = documentsByEntity.get(entity);
        if (value == null) {
            throw new IllegalStateException(entity + " is not associated with the session, cannot delete unknown entity instance");
        }

        deletedEntities.add(entity);
        includedDocumentsById.remove(value.getId());
        if (_countersByDocId != null) {
            _countersByDocId.remove(value.getId());
        }
        _knownMissingIds.add(value.getId());
    }
514896
public void deleteCascades(Object entity) {
		if (entity != null) {
			List<Field> fields = ClassUtil.getAnnotatedFields(entity.getClass(), Reference.class);
			for (Field field : fields) {
				Cascade[] cascades = ClassUtil.getFieldAnnotationValue("cascade", field, Reference.class, Cascade[].class);
				if (Arrays.asList(cascades).contains(Cascade.DELETE)) {
					Object referencedEntity = ClassUtil.getValueOfField(field, entity);
					if(referencedEntity != null){
						try {
							apitraryDaoSupport.resolveApitraryEntityId(referencedEntity);
							apitraryDaoSupport.delete(referencedEntity);
						} catch (ApitraryOrmIdException aoie) {
							/*
							 * TODO find better way for exception without breaking th cascade flow
							 */
							log.warn(aoie);
						}
					}
				}
			}
		}
	}
227406
public function deleteAllRelations($entity)
    {
        $this->deleteNotes($entity);
        $this->deleteAddresses($entity);
        $this->deleteEmails($entity);
        $this->deleteFaxes($entity);
        $this->deleteSocialMediaProfiles($entity);
        $this->deletePhones($entity);
        $this->deleteUrls($entity);
    }
123779
protected function _validateDelete($entity)
    {
        $relationships = $entity->getEntityDescription()->getRelationships();

        foreach ($relationships as $name => $relationship) {
            if ($relationship->isManyToOne() || $relationship->isManyToMany()) {
                continue;
            }

            if ($relationship->getDeleteRule()    ==  AnDomain::DELETE_CASCADE
                 || $relationship->getDeleteRule() ==  AnDomain::DELETE_DESTROY
            ) {
                $property = $relationship->getName();
                $entities = $entity->getData($property);

                if (!$entities) {
                    continue;
                }
                //someone else is responsible for deleteing the relations
                //good for mass deletion. i.e. node and edges
                if ($relationship->getDeleteRule() == AnDomain::DELETE_IGNORE) {
                    continue;
                } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DESTROY) {
                    if ($relationship->isOneToOne()) {
                        $query = AnDomainQuery::getInstance($relationship->getChildRepository(), $entities->getIdentityId());
                    } else {
                        $query = $entities->getQuery();
                    }

                    $relationship->getChildRepository()->destroy($query);
                    continue;
                } else {
                    if ($relationship->isOneToOne()) {
                        $entities = array($entities);
                    }

                    foreach ($entities as $entity) {
                        //if the cascading fails for the related entities then
                        //nullify the property in the failed entity 
                        if (!$entity->delete() && $entity->getObject()) {
                            $entity->set($relationship->getChildKey(), null);
                        }
                    }
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DENY) {
                //don't state change if there at least one entity left
                $count = $entity->getData($relationship->getName())->limit(0, 0)->getTotal();

                if ($count > 0) {
                    $entity->reset();

                    return false;
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_NULLIFY) {
                //@TODO you should set the values to null directly rather
                //then instantiating them
                $entities = $entity->getData($relationship->getName())->fetchSet();
                $property = $relationship->getChildKey();
                foreach ($entities as $entity) {
                    $entity->set($property, null);
                }
            }
        }

        return true;
    }
1170886
public function deleteAddresses($entity)
    {
        // clear addresses
        if ($entity->getAccountAddresses()) {
            foreach ($entity->getAccountAddresses() as $accountAddresses) {
                $this->em->remove($accountAddresses->getAddress());
                $this->em->remove($accountAddresses);
            }
        }
    }