mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
Model类增加静态更新方法 update
This commit is contained in:
@@ -546,10 +546,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建数据并写入
|
* 写入数据
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $data 数据 支持数组或者对象
|
* @param array $data 数据数组
|
||||||
* @return void
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public static function create($data = [])
|
public static function create($data = [])
|
||||||
{
|
{
|
||||||
@@ -557,6 +557,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $model->isUpdate(false)->save($data);
|
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
|
* @access public
|
||||||
@@ -690,20 +702,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $model::where($foreignKey, $this->data[$localKey]);
|
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
|
* @access protected
|
||||||
|
|||||||
@@ -1324,6 +1324,7 @@ abstract class Driver
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$fields = array_keys($bind);
|
$fields = array_keys($bind);
|
||||||
|
$result = [];
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
if (!in_array($key, $fields, true)) {
|
if (!in_array($key, $fields, true)) {
|
||||||
if ($this->config['fields_strict']) {
|
if ($this->config['fields_strict']) {
|
||||||
|
|||||||
Reference in New Issue
Block a user