src/Titon/Model/Model.php
public function delete(array $options = []) {
        $options = $options + ['atomic' => true];
        $id = $this->get($this->primaryKey);

        if (!$id) {
            throw new MissingPrimaryKeyException(sprintf('Cannot delete %s record if no ID is present', get_class($this)));
        }

        $model = $this;
        $operation = function() use ($model, $id, $options) {
            if ($count = $model->getRepository()->delete($id, $options)) {
                $model->flush();

                return $count;
            }

            return 0;
        };

        // Wrap in a transaction if atomic
        if ($options['atomic']) {
            try {
                $count = $this->getRepository()->getDriver()->transaction($operation);
            } catch (Exception $e) {
                return 0;
            }
        } else {
            $count = call_user_func($operation);
        }

        return $count;
    }
public function delete(array $options = []) {
        $options = $options + ['atomic' => true];
        $id = $this->get($this->primaryKey);

        if (!$id) {
            throw new MissingPrimaryKeyException(sprintf('Cannot delete %s record if no ID is present', get_class($this)));
        }

        $model = $this;
        $operation = function() use ($model, $id, $options) {
            if ($count = $model->getRepository()->delete($id, $options)) {
                $model->flush();

                return $count;
            }

            return 0;
        };

        // Wrap in a transaction if atomic
        if ($options['atomic']) {
            try {
                $count = $this->getRepository()->getDriver()->transaction($operation);
            } catch (Exception $e) {
                return 0;
            }
        } else {
            $count = call_user_func($operation);
        }

        return $count;
    }
public function delete ( array $ options = [ ] ) { $ options = $ options + [ 'atomic' => true ] ; $ id = $ this -> get ( $ this -> primaryKey ) ; if ( ! $ id ) { throw new MissingPrimaryKeyException ( sprintf ( 'Cannot delete %s record if no ID is present' , get_class ( $ this ) ) ) ; } $ model = $ this ; $ operation = function ( ) use ( $ model , $ id , $ options ) { if ( $ count = $ model -> getRepository ( ) -> delete ( $ id , $ options ) ) { $ model -> flush ( ) ; return $ count ; } return 0 ; } ; // Wrap in a transaction if atomic if ( $ options [ 'atomic' ] ) { try { $ count = $ this -> getRepository ( ) -> getDriver ( ) -> transaction ( $ operation ) ; } catch ( Exception $ e ) { return 0 ; } } else { $ count = call_user_func ( $ operation ) ; } return $ count ; }
Delete the record that is currently present in the model instance.

@see \Titon\Db\Repository::delete()

@param array $options {
@type bool $atomic      Will wrap the delete query and all nested queries in a transaction
}
@return int
@throws \Titon\Model\Exception\MissingPrimaryKeyException
Delete the record that is currently present in the model instance .