From 275d04d316dee56ece9d65051f8229d55f183971 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 18:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 486f08d8..b5d21680 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -256,8 +256,7 @@ class BelongsToMany extends Relation $pk = $this->parent->getPk(); $pivot[$this->localKey] = $this->parent->$pk; $pivot[$this->foreignKey] = $id; - $query = clone $this->parent->db(); - return $query->table($this->middle)->insert($pivot); + return $this->query->table($this->middle)->insert($pivot); } else { throw new Exception('miss relation data'); } @@ -288,8 +287,7 @@ class BelongsToMany extends Relation if (isset($id)) { $pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id; } - $query = clone $this->parent->db(); - $query->table($this->middle)->where($pivot)->delete(); + $this->query->table($this->middle)->where($pivot)->delete(); // 删除关联表数据 if (isset($id) && $relationDel) {