From e3320cd3f6bfef3e57a212d689d7d6b29fec15f2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 13 Dec 2017 17:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=A4=9A=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=9A=84save=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 0c9f8375..841bf92a 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -467,7 +467,7 @@ class BelongsToMany extends Relation $ids = (array) $id; foreach ($ids as $id) { $pivot[$this->foreignKey] = $id; - $this->pivot->insert($pivot, true); + $this->pivot->name($this->middle)->insert($pivot, true); $result[] = $this->newPivot($pivot); } if (count($result) == 1) { @@ -505,7 +505,7 @@ class BelongsToMany extends Relation if (isset($id)) { $pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id; } - $this->pivot->where($pivot)->delete(); + $this->pivot->name($this->middle)->where($pivot)->delete(); // 删除关联表数据 if (isset($id) && $relationDel) { $model = $this->model; @@ -527,7 +527,7 @@ class BelongsToMany extends Relation 'updated' => [], ]; $pk = $this->parent->getPk(); - $current = $this->pivot->where($this->localKey, $this->parent->$pk) + $current = $this->pivot->name($this->middle)->where($this->localKey, $this->parent->$pk) ->column($this->foreignKey); $records = []; @@ -571,7 +571,7 @@ class BelongsToMany extends Relation { if (empty($this->baseQuery) && $this->parent->getData()) { $pk = $this->parent->getPk(); - $table = $this->pivot->getTable(); + $table = $this->pivot->getTable($this->middle); $this->query->join($table . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); $this->baseQuery = true; }