From 4b6a39f6d3d95c36bd31ff56a125927f6c18f4b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 23:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= 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, 4 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index a832c5d5..37d07eec 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -239,9 +239,11 @@ class BelongsToMany extends Relation $result = false; foreach ($dataSet as $key => $data) { if (!$samePivot) { - $pivot = isset($pivot[$key]) ? $pivot[$key] : []; + $pivotData = isset($pivot[$key]) ? $pivot[$key] : []; + } else { + $pivotData = $pivot; } - $result = $this->attach($data, $pivot); + $result = $this->attach($data, $pivotData); } return $result; }