src/Db/Orm/ActiveRecord.php
public function update($runValidation = true, $attributeNames = null)
    {
        $validationPromise = $runValidation
            ? new LazyPromise(function() use ($attributeNames) {
                return $this->validate($attributeNames);
            })
            : Reaction\Promise\resolveLazy(true);
        return $validationPromise
            ->otherwiseLazy(function() {
                Reaction::info('Model not updated due to validation error in {method}.', ['method' => __METHOD__]);
                return reject(new ValidationError("Model validation error"));
            })->thenLazy(function() use ($attributeNames) {
                if (!$this->isTransactional(self::OP_UPDATE)) {
                    return $this->updateInternal($attributeNames);
                }

                $transaction = static::getDb()->createTransaction();
                return $transaction->begin()->then(
                    function(ConnectionInterface $connection) use ($attributeNames) {
                        return $this->updateInternal($attributeNames, $connection);
                    }
                )->then(
                    function($result) use ($transaction) {
                        return $transaction->commit()->then(function() use ($result) {
                            return $result;
                        });
                    },
                    function($exception) use ($transaction) {
                        return $transaction->rollBack()->then(
                            function() use ($exception) { throw $exception; },
                            function($e) use ($exception) { throw $exception; }
                        );
                    }
                );
            });
    }
public function update($runValidation = true, $attributeNames = null)
    {
        $validationPromise = $runValidation
            ? new LazyPromise(function() use ($attributeNames) {
                return $this->validate($attributeNames);
            })
            : Reaction\Promise\resolveLazy(true);
        return $validationPromise
            ->otherwiseLazy(function() {
                Reaction::info('Model not updated due to validation error in {method}.', ['method' => __METHOD__]);
                return reject(new ValidationError("Model validation error"));
            })->thenLazy(function() use ($attributeNames) {
                if (!$this->isTransactional(self::OP_UPDATE)) {
                    return $this->updateInternal($attributeNames);
                }

                $transaction = static::getDb()->createTransaction();
                return $transaction->begin()->then(
                    function(ConnectionInterface $connection) use ($attributeNames) {
                        return $this->updateInternal($attributeNames, $connection);
                    }
                )->then(
                    function($result) use ($transaction) {
                        return $transaction->commit()->then(function() use ($result) {
                            return $result;
                        });
                    },
                    function($exception) use ($transaction) {
                        return $transaction->rollBack()->then(
                            function() use ($exception) { throw $exception; },
                            function($e) use ($exception) { throw $exception; }
                        );
                    }
                );
            });
    }
Saves the changes to this active record into the associated database table.

This method performs the following steps in order:

1. call [[beforeValidate()]] when `$runValidation` is `true`. If [[beforeValidate()]]
returns `false`, the rest of the steps will be skipped;
2. call [[afterValidate()]] when `$runValidation` is `true`. If validation
failed, the rest of the steps will be skipped;
3. call [[beforeSave()]]. If [[beforeSave()]] returns `false`,
the rest of the steps will be skipped;
4. save the record into database. If this fails, it will skip the rest of the steps;
5. call [[afterSave()]];

In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
[[EVENT_AFTER_VALIDATE]], [[EVENT_BEFORE_UPDATE]], and [[EVENT_AFTER_UPDATE]]
will be raised by the corresponding methods.

Only the [[dirtyAttributes|changed attribute values]] will be saved into database.

For example, to update a customer record:

```php
$customer = Customer::findOne($id);
$customer->name = $name;
$customer->email = $email;
$customer->update();
```

Note that it is possible the update does not affect any row in the table.
In this case, this method will return 0. For this reason, you should use the following
code to check if update() is successful or not:

```php
if ($customer->update() !== false) {
// update successful
} else {
// update failed
}
```

@param bool $runValidation whether to perform validation (calling [[validate()]])
before saving the record. Defaults to `true`. If the validation fails, the record
will not be saved to the database and this method will return `false`.
@param array $attributeNames list of attributes that need to be saved. Defaults to `null`,
meaning all attributes that are loaded from DB will be saved.
@return LazyPromiseInterface with int|false the number of rows affected, or false if validation fails
or [[beforeSave()]] stops the updating process.
being updated is outdated.
@throws \Exception|\Throwable in case update failed.