From 340abd05e5cc8febbcbb362277b7498522b21242 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 18:12:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BBelongsToMany=E7=B1=BB?= =?UTF-8?q?=E7=9A=84saveall=E6=96=B9=E6=B3=95=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E4=B8=AA=E5=8F=82=E6=95=B0=20=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=8C=87=E5=AE=9A=E9=A2=9D=E5=A4=96=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=80=E8=87=B4?= 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, 6 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 53f344a6..55daceba 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -231,13 +231,17 @@ class BelongsToMany extends Relation * @access public * @param array $dataSet 数据集 * @param array $pivot 中间表额外数据 + * @param bool $samePivot 额外数据是否相同 * @return integer */ - public function saveAll(array $dataSet, array $pivot = []) + public function saveAll(array $dataSet, array $pivot = [], $samePivot = false) { $result = false; foreach ($dataSet as $key => $data) { - $result = $this->attach($data, !empty($pivot) ? $pivot[$key] : []); + if (!$samePivot) { + $pivot = !empty($pivot) ? $pivot[$key] : []; + } + $result = $this->attach($data, $pivot); } return $result; }