Commit 6cf7d87c by Qiang Xue

Merge pull request #2263 from dizews/convert-database-type-to-php

Convert database type to php
parents 3bc5dbed a97f6387
...@@ -115,6 +115,7 @@ Yii Framework 2 Change Log ...@@ -115,6 +115,7 @@ Yii Framework 2 Change Log
- Enh: Added `yii\web\View::POS_LOAD` (qiangxue) - Enh: Added `yii\web\View::POS_LOAD` (qiangxue)
- Enh: Added `yii\web\Response::clearOutputBuffers()` (qiangxue) - Enh: Added `yii\web\Response::clearOutputBuffers()` (qiangxue)
- Enh: Improved `QueryBuilder::buildLimit()` to support big numbers (qiangxue) - Enh: Improved `QueryBuilder::buildLimit()` to support big numbers (qiangxue)
- Enh:#2211: Added typecast database types into php types (dizews)
- Enh #2240: Improved `yii\web\AssetManager::publish()`, `yii\web\AssetManager::getPublishedPath()` and `yii\web\AssetManager::getPublishedUrl()` to support aliases (vova07) - Enh #2240: Improved `yii\web\AssetManager::publish()`, `yii\web\AssetManager::getPublishedPath()` and `yii\web\AssetManager::getPublishedUrl()` to support aliases (vova07)
- Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue) - Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue)
- Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue) - Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue)
......
...@@ -275,6 +275,29 @@ class ActiveRecord extends BaseActiveRecord ...@@ -275,6 +275,29 @@ class ActiveRecord extends BaseActiveRecord
} }
/** /**
* @inheritdoc
*/
public static function create($row)
{
$record = static::instantiate($row);
$columns = array_flip($record->attributes());
$schema = static::getTableSchema();
foreach ($row as $name => $value) {
if (isset($columns[$name])) {
if ($schema->getColumn($name) !== null) {
$record->setAttribute($name, $schema->getColumn($name)->typecast($value));
} else {
$record->setAttribute($name, $value);
}
} else {
$record->$name = $value;
}
}
$record->setOldAttributes($record->getAttributes());
return $record;
}
/**
* Inserts a row into the associated database table using the attribute values of this record. * Inserts a row into the associated database table using the attribute values of this record.
* *
* This method performs the following steps in order: * This method performs the following steps in order:
......
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