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; }