Commit d0175672 by Vladimir Zbrailov

override create

parent 903f5618
......@@ -275,6 +275,26 @@ class ActiveRecord extends BaseActiveRecord
}
/**
* @param array $row
* @return static
*/
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])) {
$record->setAttribute($name, $schema->getColumn($name)->typecast($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.
*
* This method performs the following steps in order:
......
......@@ -1002,11 +1002,8 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
$record = static::instantiate($row);
$columns = array_flip($record->attributes());
/* @var $schema TableSchema */
$schema = static::getDb()->getTableSchema(static::tableName());
foreach ($row as $name => $value) {
if (isset($columns[$name])) {
$value = $schema->getColumn($name)->typecast($value);
$record->_attributes[$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