mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 11:39:41 +08:00
Fix #18993: Load defaults by attributes() in yii\db\ActiveRecord::loadDefaultValues()
This commit is contained in:
@ -28,6 +28,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #18909: Fix bug with binding default action parameters for controllers (bizley)
|
||||
- Bug #18955: Check `yiisoft/yii2-swiftmailer` before using as default mailer in `yii\base\Application` (WinterSilence)
|
||||
- Bug #18988: Fix default value of `yii\console\controllers\MessageController::$translator` (WinterSilence)
|
||||
- Bug #18993: Load defaults by `attributes()` in `yii\db\ActiveRecord::loadDefaultValues()` (WinterSilence)
|
||||
|
||||
|
||||
2.0.43 August 09, 2021
|
||||
|
||||
@ -115,9 +115,13 @@ class ActiveRecord extends BaseActiveRecord
|
||||
*/
|
||||
public function loadDefaultValues($skipIfSet = true)
|
||||
{
|
||||
foreach (static::getTableSchema()->columns as $column) {
|
||||
if ($column->defaultValue !== null && (!$skipIfSet || $this->{$column->name} === null)) {
|
||||
$this->{$column->name} = $column->defaultValue;
|
||||
$columns = static::getTableSchema()->columns;
|
||||
foreach ($this->attributes() as $name) {
|
||||
if (isset($columns[$name])) {
|
||||
$defaultValue = $columns[$name]->defaultValue;
|
||||
if ($defaultValue !== null && (!$skipIfSet || $this->getAttribute($name) === null)) {
|
||||
$this->setAttribute($name, $defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user