Skip to content

Commit

Permalink
改进
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed May 30, 2024
1 parent 47f7e44 commit cd418d0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/model/relation/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,10 @@ public function attach($data, array $pivot = [])
$ids = (array) $id;
foreach ($ids as $id) {
$pivot[$this->foreignKey] = $id;
$this->pivot->replace()
->exists(false)
->data([])
->save($pivot);

$result[] = $this->pivot->newInstance($pivot, [
[$this->localKey, '=', $this->parent->getKey(), null],
[$this->foreignKey, '=', $id, null],
]);

$object = $this->newPivot();
$object->replace()->save($pivot);
$result[] = $object;
}

if (count($result) == 1) {
Expand Down

0 comments on commit cd418d0

Please sign in to comment.