Delete entity

@throws \Rio\Exception
331134
public function delete()
    {
        $query = sprintf(
            "DELETE FROM `{$this->table}` WHERE `%s` = %s",
            $this->primary,
            $this->adapter->getDriver()->quote($this->uid, $this->properties[$this->primary]['type'])
        );

        $statement = $this->adapter->getDriver()->query($query);

        if ($statement->rowsAffected() === 0) {
            throw new Exception('Failed to delete entity "' . CamelCase::to($this->table) . ' #' . $this->uid . '"');
        }

        $this->modified = null;
        $this->uid = null;
    }
367887
@Override
	public void delete(final T entity) {
		String id = null;
		try {
			id = (String) arangoOperations.getConverter().getMappingContext().getPersistentEntity(domainClass)
					.getIdProperty().getField().get(entity);
		} catch (final IllegalAccessException e) {
			e.printStackTrace();
		}
		arangoOperations.delete(id, domainClass);
	}
1192853
public function delete ($Model)
    {
        $entity   = $Model->getEntity();
        $entityId = $entity->getId();

        // Clear cache first
        if (isset($this->cache[$entityId])) {
            unset($this->cache[$entityId]);
        }

        $this->em->remove($entity);
        $this->em->flush();
    }
966868
public function delete()
    {
        $list = StorageLocation::getList();
        foreach ($list as $item) {
            if ($item->getTypeObject()->getHandle() == $this->getHandle()) {
                throw new \Exception(t('Please remove all storage locations using this storage type.'));
            }
        }

        $em = \ORM::entityManager();
        $em->remove($this);
        $em->flush();

        return true;
    }
1143165
public function handle(Entity $entity): void
    {
        $this->trash = $entity->getEntityAttributeValueTrash();

        // Wrap the whole process inside database transaction
        $connection = $entity->getConnection();
        $connection->beginTransaction();

        try {
            foreach ($entity->getEntityAttributes() as $attribute) {
                if ($entity->relationLoaded($relation = $attribute->getAttribute('slug'))) {
                    $relationValue = $entity->getRelationValue($relation);

                    if ($relationValue instanceof ValueCollection) {
                        foreach ($relationValue as $value) {
                            // Set attribute value's entity_id since it's always null,
                            // because when RelationBuilder::build is called very early
                            $value->setAttribute('entity_id', $entity->getKey());
                            $this->saveOrTrashValue($value);
                        }
                    } elseif (! is_null($relationValue)) {
                        // Set attribute value's entity_id since it's always null,
                        // because when RelationBuilder::build is called very early
                        $relationValue->setAttribute('entity_id', $entity->getKey());
                        $this->saveOrTrashValue($relationValue);
                    }
                }
            }

            if ($this->trash->count()) {
                // Fetch the first item's class to know the model used for deletion
                $class = get_class($this->trash->first());

                // Let's batch delete all the values based on their ids
                $class::whereIn('id', $this->trash->pluck('id'))->delete();

                // Now, empty the trash
                $this->trash = collect([]);
            }
        } catch (Exception $e) {
            // Rollback transaction on failure
            $connection->rollBack();

            throw $e;
        }

        // Commit transaction on success
        $connection->commit();
    }
139279
public function detach($entity) {
        if (!is_string($entity) && !is_object($entity))
            throw new \Exception('Entity must be a string or an object');

        if (is_object($entity)) {
            if (!$entity instanceof Entity)
                throw new \Exception('Entity must an instance of MidiChloriansPHP\mvc\model\Entity');

            $entity = $this->getEntityHash($entity);
        }

        if ($this->isAttached($entity))
            unset($this->_entities[$entity]);
    }
792212
protected function HLDelete($entity)
    {
        $return = [];
        $id = $this->HLGetIdByCode($entity);
        if ($id) {
            $res = HighloadBlockTable::delete($id);
            if ($res->isSuccess()) {
                $return[] = "Delete highload block {$entity} ({$id})";
            } else {
                throw new Exception("Can't delete {$entity} ({$id}) highload block: " . implode(', ', $res->getErrorMessages()));
            }
        } else {
            throw new Exception("Hl entity with name {$entity} does not exist");
        }

        return $return;
    }
969369
public function destroy(Entity $entity)
    {
        if ($entity->isExists()) {

            // enable logical delete ?
            if ($entity->hasAttribute('active')) {
                $attributes = [];
                $attributes['active'] = 0;
                if ($entity->hasAttribute('deleted_at')) $attributes['deleted_at'] = time();
                $this->update($attributes, $entity->getPrimaryValue());
            } else {
                $this->delete($entity->getPrimaryValue());
            }
        }
    }
1172143
public function deleteObject($entity)
    {
        try {
            return (bool) $entity->delete();
        } catch (\Exception $ex) {
            Yii::$app->getErrorHandler()->logException($ex);

            return false;
        }
    }
856409
public function delete(Entity $entity) {
    $this->remove($entity);
    $this->_em->flush();
    
    return $this;
  }
1139376
public function delete()
    {
        $keys = $this->getList();
        foreach ($keys as $key) {
            $this->entityManager->remove($key);
        }
        $this->entityManager->flush();
    }
226327
public function delete() {
        $sql = new Sql();
        $transaction = Database::instance()->db()->inTransaction();

        if (!$transaction) {
            Database::instance()->db()->beginTransaction();
        }

        foreach ($this->_fields as $field) {
            if ($field->primary == false) {
                if ($field->foreign != null) {
                    switch ($field->foreign->type()) {
                        case ForeignKey::ONE_TO_ONE :
                            /** if it's a one to one relation, we delete the linked Entity */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    if ($field->foreign->type() == Builder::JOIN_INNER) {
                                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                    }
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                }

                                $field->value->delete();
                            }
                            break;

                        case ForeignKey::MANY_TO_ONE :
                            if ($field->value != null) {
                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    if (gettype($field->value) != 'object') {
                                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                    }
                                    if (get_class($field->value) != 'System\Collection\Collection') {
                                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                    }

                                    $field->value->delete();
                                }
                            }
                            break;

                        case ForeignKey::ONE_TO_MANY :
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                    foreach ($field->value as $entity) {
                                        if ($entity != null) {
                                            $field->value->delete();
                                        }
                                    }
                                }
                            }
                            break;

                        case ForeignKey::MANY_TO_MANY :
                            /** Here we must delete from the referenced table and the relation table too */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    $currentEntity = $field->foreign->entity();
                                    $currentField = $field->foreign->field();
                                    $referenceEntity = $field->foreign->referenceEntity();
                                    $referenceField = $field->foreign->referenceField();

                                    $current = strtolower($currentEntity . $currentField);
                                    $reference = strtolower($referenceEntity . $referenceField);
                                    $table = [$current, $reference];
                                    sort($table, SORT_STRING);
                                    $table = ucfirst($table[0] . $table[1]);

                                    $sql = new Sql();
                                    $sql->query('orm-delete-many', 'DELETE FROM ' . $table . ' WHERE ' . $this->name() . '_' . $field->foreign->referenceField() . ' = ' . $this->_fields[$this->_primary]);
                                    $sql->fetch('orm-delete-many');

                                    /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                    foreach ($field->value as $entity) {
                                        if ($entity != null) {
                                            $field->value->delete();
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }
                else {
                    switch ($field->type) {
                        case Field::FILE :
                            if ($field->unique) {
                                $field->value->delete();
                            }
                            break;
                    }
                }
            }
        }

        $query = 'DELETE FROM ' . $this->_name . ' WHERE ' . $this->_fields[$this->_primary]->name . ' = ' . $this->_fields[$this->_primary]->value;

        $sql->query('delete_' . $this->_name . '_' . $this->_token, $query);
        $sql->fetch('delete_' . $this->_name . '_' . $this->_token, Sql::PARAM_FETCHDELETE);

        if (!$transaction) {
            Database::instance()->db()->commit();
        }
    }
202655
public function remove(EntityRemoved $event)
    {
        $entity = $event->getEntity();
        $collection = $event->getCollection();
        $this->deleteRelation($entity, $collection);
    }
659855
public function delete($entity)
    {
        $eloquentModel = $this->getEloquentModel($entity, true);

        $this->updateRelations($eloquentModel, 'delete');

        $eloquentModel->delete();
    }
791874
public function delete($entity)
    {
        $identifier   = $this->getIdentifier($entity);
        $affectedRows = $this->connection->delete($this->tableName, $identifier);

        if ($affectedRows == 0) {
            throw new OrmException("Entity not found.");
        }
    }
1011757
public function delete()
    {
        if (!$this->isLoaded()) {
            //Nothing to do, do we need an exception here?
            return;
        }

        $this->dispatch('delete', new DocumentEvent($this));

        //Performing deletion
        $this->odm->collection(static::class)->deleteOne(['_id' => $this->primaryKey()]);
        $this->setField('_id', null, false);
        //Done with deletion

        $this->dispatch('deleted', new DocumentEvent($this));
    }
129473
public function deleteEntity($entity)
    {
        if (!$this->isExtendedField($entity)) {
            return parent::deleteEntity($entity);
        }

        // Pre-delete event (same as core).
        $id    = $entity->getId();
        $event = $this->dispatchEvent('pre_delete', $entity);
        $this->getRepository()->deleteEntity($entity);

        $schema        = $this->getSchemaDefinition($entity->getName(), $entity->getType());
        $secure        = 'extendedFieldSecure' === $entity->getObject() ? '_secure' : '';
        $extendedTable = MAUTIC_TABLE_PREFIX.'lead_fields_leads_'.$schema['type'].$secure.'_xref';
        $column        = [
            'lead_field_id' => $entity->getId(),
        ];
        $this->em->getConnection()->delete(
            $extendedTable,
            $column
        );

        // Post-delete event (same as core).
        // set the id for use in events
        $entity->deletedId = $id;
        $this->dispatchEvent('post_delete', $entity, false, $event);
    }