Skip to content

Commit

Permalink
改进saveall方法对多主键的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Apr 20, 2023
1 parent 460abd0 commit 10528eb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Model.php
Expand Up @@ -769,16 +769,20 @@ public function saveAll(iterable $dataSet, bool $replace = true): Collection

$pk = $this->getPk();

if (is_string($pk) && $replace) {
$auto = true;
}

$result = [];

$suffix = $this->getSuffix();

foreach ($dataSet as $key => $data) {
if ($this->exists || (!empty($auto) && isset($data[$pk]))) {
if ($replace) {
$exists = true;
foreach ((array) $pk as $field) {
if (!isset($data[$field])) {
$exists = false;
}
}
}

if ($replace && !empty($exists)) {
$result[$key] = static::update($data, [], [], $suffix);
} else {
$result[$key] = static::create($data, $this->field, $this->replace, $suffix);
Expand Down

0 comments on commit 10528eb

Please sign in to comment.