ManaPHP\Mvc\Model::delete PHP Метод

delete() публичный Метод

$robot = Robots::findFirst("id=100"); $robot->delete(); foreach (Robots::find("type = 'mechanical'") as $robot) { $robot->delete(); }
public delete ( ) : void
Результат void
    public function delete()
    {
        $writeConnection = $this->getWriteConnection();
        $primaryKeys = $this->modelsMetadata->getPrimaryKeyAttributes($this);
        if (count($primaryKeys) === 0) {
            throw new ModelException('`:model` model must define a primary key in order to perform delete operation', ['model' => get_class($this)]);
        }
        if ($this->_fireEventCancel('beforeDelete') === false) {
            throw new ModelException('`:model` model cannot be deleted because it has been cancel.', ['model' => get_class($this)]);
        }
        $conditions = [];
        foreach ($primaryKeys as $attributeField) {
            if (!isset($this->{$attributeField})) {
                throw new ModelException('`:model` model cannot be deleted because the primary key attribute: `:column` was not set', ['model' => get_class($this), 'column' => $attributeField]);
            }
            $conditions[$attributeField] = $this->{$attributeField};
        }
        $writeConnection->delete($this->getSource(), $conditions);
        $this->_fireEvent('afterDelete');
    }