src/Db/Orm/BaseActiveRecord.php
public function delete()
    {
        if ($this->beforeDelete()) {
            // 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)->then(
                function($result) use ($lock) {
                    if ($lock !== null && !$result) {
                        throw new StaleObjectException('The object being deleted is outdated.');
                    }
                    $this->_oldAttributes = null;
                    $this->afterDelete();
                }
            );
        } else {
            return reject(false);
        }
    }
public function delete()
    {
        if ($this->beforeDelete()) {
            // 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)->then(
                function($result) use ($lock) {
                    if ($lock !== null && !$result) {
                        throw new StaleObjectException('The object being deleted is outdated.');
                    }
                    $this->_oldAttributes = null;
                    $this->afterDelete();
                }
            );
        } else {
            return reject(false);
        }
    }
Deletes the table row corresponding to this active record.

This method performs the following steps in order:

1. call [[beforeDelete()]]. If the method returns `false`, it will skip the
rest of the steps;
2. delete the record from the database;
3. call [[afterDelete()]].

In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]]
will be raised by the corresponding methods.

@return ExtendedPromiseInterface 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.
being deleted is outdated.
@throws Exception in case delete failed.