From 6433f8fdca2931cd7232b857b4a7d91f61f19da3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 23:40:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 55daceba..a832c5d5 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -239,7 +239,7 @@ class BelongsToMany extends Relation $result = false; foreach ($dataSet as $key => $data) { if (!$samePivot) { - $pivot = !empty($pivot) ? $pivot[$key] : []; + $pivot = isset($pivot[$key]) ? $pivot[$key] : []; } $result = $this->attach($data, $pivot); } From 4b6a39f6d3d95c36bd31ff56a125927f6c18f4b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 23:57:47 +0800 Subject: [PATCH 2/2] =?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; }