Skip to content

Commit

Permalink
改进时间字段处理
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 18, 2021
1 parent 78a4849 commit 8a2225c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/Model.php
Expand Up @@ -266,9 +266,8 @@ public function getName(): string
*/
public function newInstance(array $data = [], $where = null): Model
{
$this->readDataType($data);

$model = new static($data);
$model->readDataType();

if ($this->connection) {
$model->setConnection($this->connection);
Expand Down
14 changes: 6 additions & 8 deletions src/model/concern/Attribute.php
Expand Up @@ -510,17 +510,15 @@ protected function getValue(string $name, $value, $relation = false)
/**
* 读取数据类型处理
* @access protected
* @param array $data 数据
* @return void
*/
protected function readDataType(array &$data): void
protected function readDataType(): void
{
foreach ($data as $name => &$value) {
if (isset($this->type[$name])) {
// 类型转换
$value = $this->readTransform($value, $this->type[$name]);
} elseif ($this->autoWriteTimestamp && in_array($name, [$this->createTime, $this->updateTime])) {
$value = $this->getTimestampValue($value);
foreach ($this->data as $key => $value) {
if (isset($this->type[$key])) {
$this->data[$key] = $this->readTransform($value, $this->type[$key]);
} elseif ($this->autoWriteTimestamp && in_array($key, [$this->createTime, $this->updateTime])) {
$this->data[$key] = $this->getTimestampValue($value);
}
}
}
Expand Down

0 comments on commit 8a2225c

Please sign in to comment.