mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-03 14:02:47 +08:00
Model类增加静态更新方法 update
This commit is contained in:
@@ -546,10 +546,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据并写入
|
||||
* 写入数据
|
||||
* @access public
|
||||
* @param mixed $data 数据 支持数组或者对象
|
||||
* @return void
|
||||
* @param array $data 数据数组
|
||||
* @return integer
|
||||
*/
|
||||
public static function create($data = [])
|
||||
{
|
||||
@@ -557,6 +557,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return $model->isUpdate(false)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @access public
|
||||
* @param array $data 数据数组
|
||||
* @return integer
|
||||
*/
|
||||
public static function update($data = [])
|
||||
{
|
||||
$model = new static();
|
||||
return $model->isUpdate(true)->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找单条记录
|
||||
* @access public
|
||||
@@ -690,20 +702,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return $model::where($foreignKey, $this->data[$localKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化模型
|
||||
* @access public
|
||||
* @param array $config 配置参数
|
||||
* @return object
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new static();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据库对象
|
||||
* @access protected
|
||||
|
||||
@@ -1324,6 +1324,7 @@ abstract class Driver
|
||||
return [];
|
||||
}
|
||||
$fields = array_keys($bind);
|
||||
$result = [];
|
||||
foreach ($data as $key => $val) {
|
||||
if (!in_array($key, $fields, true)) {
|
||||
if ($this->config['fields_strict']) {
|
||||
|
||||
Reference in New Issue
Block a user