From 48b856a7f12a29e4f34cc2e0103b5cc60c261e58 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 20 Jan 2017 21:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84delete?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=B8=BB=E9=94=AE=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index cfd404ad..ebc84abd 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -991,8 +991,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return false; } + // 删除条件 + $pk = $this->getPk(); + if (isset($this->data[$pk])) { + $where = [$pk => $this->data[$pk]]; + } elseif (!empty($this->updateWhere)) { + $where = $this->updateWhere; + } else { + $where = null; + } + // 删除当前模型数据 - $result = $this->db()->delete($this->data); + $result = $this->db()->where($where)->delete(); // 关联删除 if (!empty($this->relationWrite)) {