model类的saveall方法支持调用allowField方法进行字段过滤

This commit is contained in:
thinkphp
2016-11-15 19:09:31 +08:00
parent e643514af8
commit 3d587c75c5

View File

@@ -759,9 +759,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
}
foreach ($dataSet as $key => $data) {
if (!empty($auto) && isset($data[$pk])) {
$result[$key] = self::update($data);
$result[$key] = self::update($data, [], $this->field);
} else {
$result[$key] = self::create($data);
$result[$key] = self::create($data, $this->field);
}
}
$db->commit();
@@ -979,12 +979,16 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/**
* 写入数据
* @access public
* @param array $data 数据数组
* @param array $data 数据数组
* @param array|true $field 允许字段
* @return $this
*/
public static function create($data = [])
public static function create($data = [], $field = null)
{
$model = new static();
if (!empty($field)) {
$model->allowField($field);
}
$model->isUpdate(false)->save($data, []);
return $model;
}
@@ -992,13 +996,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/**
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $where 更新条件
* @param array $data 数据数组
* @param array $where 更新条件
* @param array|true $field 允许字段
* @return $this
*/
public static function update($data = [], $where = [])
public static function update($data = [], $where = [], $field = null)
{
$model = new static();
$model = new static();
if (!empty($field)) {
$model->allowField($field);
}
$result = $model->isUpdate(true)->save($data, $where);
return $model;
}