Commit 39b0c454 by Alexander Makarov

Default values init moved to a method that should be called manually

parent b66427f8
......@@ -146,7 +146,7 @@ Yii Framework 2 Change Log
- Enh #2661: Added boolean column type support for SQLite (qiangxue)
- Enh #2670: Changed `console\Controller::globalOptions()` to `options($actionId)` to (make it possible to) differentiate options per action (hqx)
- Enh #2714: Added support for formatting time intervals relative to the current time with `yii\base\Formatter` (drenty)
- Enh #2726: ActiveRecord now fills default values on creating new instance of the model if defaults are available from DB schema (samdark)
- Enh #2726: Added `yii\db\ActiveRecord::loadDefaultValues()` that fills default values from DB schema (samdark)
- Enh #2729: Added `FilterValidator::skipOnArray` so that filters like `trim` will not fail for array inputs (qiangxue)
- Enh #2735: Added support for `DateTimeInterface` in `Formatter` (ivokund)
- Enh #2756: Added support for injecting custom `isEmpty` check for all validators (qiangxue)
......
......@@ -94,15 +94,18 @@ class ActiveRecord extends BaseActiveRecord
const OP_ALL = 0x07;
/**
* @inheritdoc
* Loads default values from database table schema
*
* @return static model instance
*/
public function init()
public function loadDefaultValues()
{
foreach ($this->getTableSchema()->columns as $column) {
if ($column->defaultValue) {
$this->{$column->name} = $column->defaultValue;
}
}
return $this;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment