mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-24 02:27:22 +08:00
changedAttributes of AfterSaveEvent contain an old values
This commit is contained in:
@@ -152,6 +152,7 @@ Yii Framework 2 Change Log
|
||||
- Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue)
|
||||
- Chg #3989: The default value for `yii\log\FileTarget::$rotateByCopy` now defaults to true to work on windows by default (cebe)
|
||||
- Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark)
|
||||
- Chg #4086: changedAttributes of AfterSaveEvent contain an old values (dizews)
|
||||
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
|
||||
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
|
||||
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
|
||||
|
||||
@@ -462,8 +462,9 @@ class ActiveRecord extends BaseActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
$changedAttributes = array_fill_keys(array_keys($values), null);
|
||||
$this->setOldAttributes($values);
|
||||
$this->afterSave(true, $values);
|
||||
$this->afterSave(true, $changedAttributes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -714,10 +714,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
throw new StaleObjectException('The object being updated is outdated.');
|
||||
}
|
||||
|
||||
$changedAttributes = [];
|
||||
foreach ($values as $name => $value) {
|
||||
$changedAttributes[$name] = $this->_oldAttributes[$name];
|
||||
$this->_oldAttributes[$name] = $this->_attributes[$name];
|
||||
}
|
||||
$this->afterSave(false, $values);
|
||||
$this->afterSave(false, $changedAttributes);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
@@ -875,7 +877,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
* the event is triggered.
|
||||
* @param boolean $insert whether this method called while inserting a record.
|
||||
* If false, it means the method is called while updating a record.
|
||||
* @param array $changedAttributes The attribute values that had changed and were saved.
|
||||
* @param array $changedAttributes The attribute values that had changed and were saved contain old values.
|
||||
*/
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user