mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进BelongsToMany类的saveall方法 增加第三个参数 用于指定额外参数是否一致
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user