Skip to content

Commit

Permalink
改进虚拟模型
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jun 21, 2023
1 parent 2393396 commit 68b011d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/model/concern/Virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use think\db\BaseQuery as Query;
use think\db\exception\DbException as Exception;
use think\Model;

/**
* 虚拟模型.
Expand Down Expand Up @@ -47,13 +48,19 @@ public function getFieldType(string $field)
/**
* 保存当前数据对象
*
* @param array $data 数据
* @param array|object $data 数据
* @param string $sequence 自增序列名
*
* @return bool
*/
public function save(array $data = [], string $sequence = null): bool
public function save(array|object $data = [], string $sequence = null): bool
{
if ($data instanceof Model) {
$data = $data->getData();
} elseif (is_object($data)) {
$data = get_object_vars($data);
}

// 数据对象赋值
$this->setAttrs($data);

Expand Down

0 comments on commit 68b011d

Please sign in to comment.