From 4fba18bc6cdaef84435b97898247c8e47d25f33c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 11 Apr 2016 11:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84destor?= =?UTF-8?q?y=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=20=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 377164fa..632d406a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -604,7 +604,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function update($data = [], $where = []) { $model = new static(); - $model->isUpdate(true)->where($where)->save($data); + $model->isUpdate(true)->save($data, $where); return $model; } @@ -662,13 +662,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 删除记录 * @access public - * @param mixed $data 主键列表 + * @param mixed $data 主键列表 支持闭包查询条件 * @return integer */ public static function destroy($data) { - $model = new static(); - $resultSet = $model->select($data); + $db = self::db(); + if ($data instanceof \Closure) { + call_user_func_array($data, [ & $db]); + $data = []; + } + $resultSet = $db->select($data); if ($resultSet) { foreach ($resultSet as $data) { $result = $data->delete();