From bf33e3175a8cb9a1391eec69b30b195bc652d464 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 20 Aug 2016 15:32:05 +0800 Subject: [PATCH] =?UTF-8?q?saveall=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E8=B0=83=E7=94=A8validate=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 09e53958..20f98266 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -744,9 +744,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->validate); } else { - $result[$key] = self::create($data); + $result[$key] = self::create($data, $this->validate); } } $db->commit(); @@ -960,12 +960,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * 写入数据 * @access public * @param array $data 数据数组 + * @param mixed $validate 数据验证规则 * @return $this */ - public static function create($data = []) + public static function create($data = [], $validate = null) { $model = new static(); - $model->isUpdate(false)->save($data, []); + $model->validate($validate)->isUpdate(false)->save($data, []); return $model; } @@ -974,12 +975,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param array $data 数据数组 * @param array $where 更新条件 + * @param mixed $validate 数据验证规则 * @return $this */ - public static function update($data = [], $where = []) + public static function update($data = [], $where = [], $validate = null) { $model = new static(); - $model->isUpdate(true)->save($data, $where); + $model->validate($validate)->isUpdate(true)->save($data, $where); return $model; }