Before deleting an existing model.

@return mixed
772478
public function beforeDelete()
    {
        $this->invites()->sync(array());
        $this->deletePages();
        $this->deletePosts();
        $this->deleteEvents();
        $this->deleteComments();
    }
1653
public function beforeSave()
    {
        if ($this->file instanceof UploadedFile) {

            if (true !== $this->owner->isNewRecord) {
                /** @var ActiveRecord $oldModel */
                $oldModel = $this->owner->findOne($this->owner->primaryKey);
                $behavior = static::getInstance($oldModel, $this->attribute);
                $behavior->cleanFiles();
            }

            $this->owner->{$this->attribute} = implode('.',
                array_filter([$this->file->baseName, $this->file->extension])
            );
        } else {
            if (true !== $this->owner->isNewRecord && empty($this->owner->{$this->attribute})) {
                $this->owner->{$this->attribute} = ArrayHelper::getValue($this->owner->oldAttributes, $this->attribute,
                    null);
            }
        }
    }
272385
public function delete()
    {
        $this->exitIfModelNotSet();

        $params = [
            'id'    => $this->model->getKey(),
            'type'  => $this->model->getDocumentType(),
            'index' => $this->model->getDocumentIndex(),
        ];

        // check if the document exists before deleting
        if ($this->connection->existsStatement($params)) {
            return $this->connection->deleteStatement($params);
        }

        return true;
    }
405819
public function beforeDelete()
    {
        foreach ($this->attributes as $attr => $options) {
            $this->ensureAttribute($attr, $options);
            $this->deleteFiles($attr);
        }
    }
1138133
public function delete()
    {
        $i = 0;
        foreach ($this->_models as $model) {
            $i += $this->dropTable($model);
        }

        return $i;
    }
622202
public function delete()
    {
        $this->eventsManager->fireEvent('model:beforeDelete', $this);

        static::query(null, $this)->where($this->_getPrimaryKeyValuePairs())->delete();

        $this->eventsManager->fireEvent('model:afterDelete', $this);

        return $this;
    }
189859
private function getPreparedDeleteById()
    {
        if (is_null($this->preparedDeleteById)) {
            $this->preparedDeleteById = $this->getServer()
                ->delete($this->tableName)
                ->where()
                ->expr($this->keyColumnName, '=', ':id');
        }

        return $this->preparedDeleteById;
    }
516068
public function delete(){
        return X::app()->db->table(self::tableName())->delete([self::$pk=>$this->{self::$pk}]);
    }
501665
public function beforeAttach()
    {
        $handler = $this->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->beforeAttach($this);
        }
    }
934115
protected function performDeleteOnModel()
    {
        if ($this->forceDeleting) {
            $this->exists = false;

            return $this->setKeysForSaveQuery($this->newModelQuery())->forceDelete();
        }

        return $this->runSoftDelete();
    }
65534
protected function beforeRun() {

		// Get model from controller
		$this->model = $this->model ?? $this->controller->model;

		// Proceed only if model is not discovered yet
		if( !isset( $this->model ) ) {

			// Read slug from url
			$slug = Yii::$app->request->get( $this->slugParam, null );

			// Try to find model using slug
			if( isset( $slug ) ) {

				if( $this->typed ) {

					// Search model using slug and type ... It works well for tables having unique slug and type
					if( isset( $this->type ) ) {

						$this->model = $this->modelService->getBySlugType( $slug, $this->type );
					}
					// Get first model of matched slug ... It works well for tables having unique slug
					else {

						$this->model = $this->modelService->getFirstBySlug( $slug, true );
					}
				}
				else {

					$this->model = $this->modelService->getBySlug( $slug );
				}
			}
			// Try to find model using id
			else {

				$id	= Yii::$app->request->get( $this->idParam, null );

				if( isset( $id ) ) {

					$this->model = $this->modelService->getById( $id );
				}
			}
		}

		if( isset( $this->model ) ) {

			$this->controller->model = $this->model;

			return true;
		}
		else {

			return false;
		}
    }
941289
public function beforeUpdate()
    {
        foreach ($this->models as $relationName => $config) {
            $this->markFilesAsPermanent($this->getRelationValues($relationName));
        }
    }
1346584
public function delete() 
	{
		$settings = static::_model();

		$result = DB::delete( $settings['table'] )
			->where( $settings['primary_key'], $this->_data_store[$settings['primary_key']] )
			->limit(1)
			->run( $settings['handler'] );

		$this->_data_store[$cache['primary_key']] = null;

		return $result;
	}
644261
public function delete()
    {
        if (true === $this->getState()->is('new')) {
            throw new \RuntimeException('You cannot delete a new model');
        }
        if (true === $this->getState()->is('deleted')) {
            return $this;
        }
        $this->getState()->setDeleting();
        return $this;
    }
654388
public function delete()
    {
        $result = false;
        
        if ($this->beforeDelete()) {
            $this->updateAttributes(static::internalUpdateValues());
            $result = true;
            $this->afterDelete();
        }
        
        return $result;
    }
684227
public function delete(){
        if($this->beforeDelete()){
            $pkConditions = $this->buildPKConditions();
            if(false !== $rst = ($this->isNew() || $this->_db->builder()->delete($this->getTable(), $pkConditions[0], $pkConditions[1]))){
                $this->_data = array();
                $this->_dirty = array();
                $this->afterDelete();
                
                return $rst;
            }
        }
        
        return false;
    }
1022714
public function delete()
    {
        if (is_null($this->getKeyName())) {
            throw new Exception('No primary key defined on model.');
        }

        // If the model doesn't exist, there is nothing to delete so we'll just return
        // immediately and not do anything else. Otherwise, we will continue with a
        // deletion process on the model, firing the proper events, and so forth.
        if (!$this->exists) {
            return;
        }

        if ($this->fireModelEvent('deleting') === false) {
            return false;
        }

        // Here, we'll touch the owning models, verifying these timestamps get updated
        // for the models. This will allow any caching to get broken on the parents
        // by the timestamp. Then we will go ahead and delete the model instance.
        $this->touchOwners();

        $this->performDeleteOnModel();

        $this->exists = false;

        // Once the model has been deleted, we will fire off the deleted event so that
        // the developers may hook into post-delete operations. We will then return
        // a boolean true as the delete is presumably successful on the database.
        $this->fireModelEvent('deleted', false);

        return true;
    }