mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
saveall方法改进对验证错误的处理 会抛出异常 并回滚
This commit is contained in:
@@ -744,9 +744,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
foreach ($dataSet as $key => $data) {
|
foreach ($dataSet as $key => $data) {
|
||||||
if (!empty($auto) && isset($data[$pk])) {
|
if (!empty($auto) && isset($data[$pk])) {
|
||||||
$result[$key] = self::update($data, [], $this->validate);
|
$result[$key] = self::update($data, [], $this->validate, true);
|
||||||
} else {
|
} else {
|
||||||
$result[$key] = self::create($data, $this->validate);
|
$result[$key] = self::create($data, $this->validate, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db->commit();
|
$db->commit();
|
||||||
@@ -961,13 +961,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param array $data 数据数组
|
* @param array $data 数据数组
|
||||||
* @param mixed $validate 数据验证规则
|
* @param mixed $validate 数据验证规则
|
||||||
* @return $this
|
* @param boolean $exception 验证失败是否抛出异常
|
||||||
|
* @return $this|false
|
||||||
*/
|
*/
|
||||||
public static function create($data = [], $validate = null)
|
public static function create($data = [], $validate = null, $exception = false)
|
||||||
{
|
{
|
||||||
$model = new static();
|
$model = new static();
|
||||||
$model->validate($validate)->isUpdate(false)->save($data, []);
|
$result = $model
|
||||||
return $model;
|
->validate($validate)
|
||||||
|
->validateFailException($exception)
|
||||||
|
->isUpdate(false)
|
||||||
|
->save($data, []);
|
||||||
|
return false === $result ? false : $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -976,13 +981,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param array $data 数据数组
|
* @param array $data 数据数组
|
||||||
* @param array $where 更新条件
|
* @param array $where 更新条件
|
||||||
* @param mixed $validate 数据验证规则
|
* @param mixed $validate 数据验证规则
|
||||||
* @return $this
|
* @param boolean $exception 验证失败是否抛出异常
|
||||||
|
* @return $this|false
|
||||||
*/
|
*/
|
||||||
public static function update($data = [], $where = [], $validate = null)
|
public static function update($data = [], $where = [], $validate = null, $exception = false)
|
||||||
{
|
{
|
||||||
$model = new static();
|
$model = new static();
|
||||||
$model->validate($validate)->isUpdate(true)->save($data, $where);
|
$result = $model
|
||||||
return $model;
|
->validate($validate)
|
||||||
|
->validateFailException($exception)
|
||||||
|
->isUpdate(true)
|
||||||
|
->save($data, $where);
|
||||||
|
return false === $result ? false : $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user