Commit 8001d234 by Qiang Xue

refactored ActiveRecord::create().

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