public function delete($id = null)
    {
        if ($this->read_only) {
            throw new Exception(['Model is read-only and cannot be deleted']);
        }

        if ($id == $this->id) {
            $id = null;
        }

        return $this->atomic(function () use ($id) {
            if ($id) {
                $c = clone $this;
                $c->load($id)->delete();

                return $this;
            } elseif ($this->loaded()) {
                if ($this->hook('beforeDelete', [$this->id]) === false) {
                    return $this;
                }
                $this->persistence->delete($this, $this->id);
                $this->hook('afterDelete', [$this->id]);
                $this->unload();

                return $this;
            } else {
                throw new Exception(['No active record is set, unable to delete.']);
            }
        });
    }
public function delete($id = null)
    {
        if ($this->read_only) {
            throw new Exception(['Model is read-only and cannot be deleted']);
        }

        if ($id == $this->id) {
            $id = null;
        }

        return $this->atomic(function () use ($id) {
            if ($id) {
                $c = clone $this;
                $c->load($id)->delete();

                return $this;
            } elseif ($this->loaded()) {
                if ($this->hook('beforeDelete', [$this->id]) === false) {
                    return $this;
                }
                $this->persistence->delete($this, $this->id);
                $this->hook('afterDelete', [$this->id]);
                $this->unload();

                return $this;
            } else {
                throw new Exception(['No active record is set, unable to delete.']);
            }
        });
    }
public function delete ( $ id = null ) { if ( $ this -> read_only ) { throw new Exception ( [ 'Model is read-only and cannot be deleted' ] ) ; } if ( $ id == $ this -> id ) { $ id = null ; } return $ this -> atomic ( function ( ) use ( $ id ) { if ( $ id ) { $ c = clone $ this ; $ c -> load ( $ id ) -> delete ( ) ; return $ this ; } elseif ( $ this -> loaded ( ) ) { if ( $ this -> hook ( 'beforeDelete' , [ $ this -> id ] ) === false ) { return $ this ; } $ this -> persistence -> delete ( $ this , $ this -> id ) ; $ this -> hook ( 'afterDelete' , [ $ this -> id ] ) ; $ this -> unload ( ) ; return $ this ; } else { throw new Exception ( [ 'No active record is set, unable to delete.' ] ) ; } } ) ; }
Delete record with a specified id. If no ID is specified
then current record is deleted.

@param mixed $id

@throws Exception

@return $this
Delete record with a specified id . If no ID is specified then current record is deleted .