protected function deleteInternal($connection = null)
    {
        if (!$this->beforeDelete()) {
            return Reaction\Promise\rejectLazy(false);
        }

        // we do not check the return value of deleteAll() because it's possible
        // the record is already deleted in the database and thus the method will return 0
        $condition = $this->getOldPrimaryKey(true);
        $lock = $this->optimisticLock();
        if ($lock !== null) {
            $condition[$lock] = $this->$lock;
        }
        return static::deleteAll($condition, [], $connection)->thenLazy(
            function($result) use ($lock) {
                if ($lock !== null && !$result) {
                    throw new StaleObjectException('The object being deleted is outdated.');
                }
                $this->setOldAttributes(null);
                $this->afterDelete();

                return $result;
            }
        );
    }
protected function deleteInternal($connection = null)
    {
        if (!$this->beforeDelete()) {
            return Reaction\Promise\rejectLazy(false);
        }

        // we do not check the return value of deleteAll() because it's possible
        // the record is already deleted in the database and thus the method will return 0
        $condition = $this->getOldPrimaryKey(true);
        $lock = $this->optimisticLock();
        if ($lock !== null) {
            $condition[$lock] = $this->$lock;
        }
        return static::deleteAll($condition, [], $connection)->thenLazy(
            function($result) use ($lock) {
                if ($lock !== null && !$result) {
                    throw new StaleObjectException('The object being deleted is outdated.');
                }
                $this->setOldAttributes(null);
                $this->afterDelete();

                return $result;
            }
        );
    }
protected function deleteInternal ( $ connection = null ) { if ( ! $ this -> beforeDelete ( ) ) { return Reaction \ Promise \ rejectLazy ( false ) ; } // we do not check the return value of deleteAll() because it's possible // the record is already deleted in the database and thus the method will return 0 $ condition = $ this -> getOldPrimaryKey ( true ) ; $ lock = $ this -> optimisticLock ( ) ; if ( $ lock !== null ) { $ condition [ $ lock ] = $ this -> $ lock ; } return static :: deleteAll ( $ condition , [ ] , $ connection ) -> thenLazy ( function ( $ result ) use ( $ lock ) { if ( $ lock !== null && ! $ result ) { throw new StaleObjectException ( 'The object being deleted is outdated.' ) ; } $ this -> setOldAttributes ( null ) ; $ this -> afterDelete ( ) ; return $ result ; } ) ; }
Deletes an ActiveRecord without considering transaction.
@param ConnectionInterface|null $connection
@return LazyPromiseInterface with int|false the number of rows deleted, or `false` if the deletion is unsuccessful for some reason.
Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
Deletes an ActiveRecord without considering transaction .