Commit 8001d234 by Qiang Xue

refactored ActiveRecord::create().

parent 6cf7d87c
......@@ -280,15 +280,14 @@ class ActiveRecord extends BaseActiveRecord
public static function create($row)
{
$record = static::instantiate($row);
$columns = array_flip($record->attributes());
$schema = static::getTableSchema();
$attributes = array_flip($record->attributes());
$columns = static::getTableSchema()->columns;
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);
}
$value = $columns[$name]->typecast($value);
}
if (isset($attributes[$name])) {
$record->setAttribute($name, $value);
} else {
$record->$name = $value;
}
......
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