From 6f51dd0e47fe9cb8157b40aadeb4f9175bfacae3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 10 Nov 2016 11:36:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=AF=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84withTrashed=E6=96=B9=E6=B3=95=20Query=E7=B1=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0removeWhereField=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 16 ++++++++++++++++ library/traits/model/SoftDelete.php | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 99ae42a4..3f4d5fd0 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -938,6 +938,22 @@ class Query } } + /** + * 去除某个查询条件 + * @access public + * @param string $field 查询字段 + * @param string $logic 查询逻辑 and or xor + * @return $this + */ + public function removeWhereField($field, $logic = 'AND') + { + $logic = strtoupper($logic); + if (isset($this->options['where'][$logic][$field])) { + unset($this->options['where'][$logic][$field]); + } + return $this; + } + /** * 指定查询数量 * @access public diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 9f7cedce..8ecf35de 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -27,7 +27,8 @@ trait SoftDelete public static function withTrashed() { $model = new static(); - return $model->db(false); + $field = $model->getDeleteTimeField(true); + return $model->db(false)->removeWhereField($field); } /**