diff --git a/src/Model.php b/src/Model.php index 761f780e..a8332e92 100644 --- a/src/Model.php +++ b/src/Model.php @@ -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);