diff --git a/RelationTrait.php b/RelationTrait.php index e3c9aa6..d423911 100644 --- a/RelationTrait.php +++ b/RelationTrait.php @@ -224,6 +224,18 @@ public function saveAll($skippedRelations = []) $query = ['and', $notDeletedFK, ['not in', $relPKAttr[0], $notDeletedPK]]; if (!empty($notDeletedPK)) { try { + $notDeletedPK = array_filter($notDeletedPK); + if (empty($notDeletedPK)) { + // new record was added and old records were deleted + $query = []; + } else { + $query = [ + 'and', + $notDeletedFK, + ['not in', $relPKAttr[0], $notDeletedPK] + ]; + } + if ($isSoftDelete) { $relModel->updateAll($this->_rt_softdelete, $query); } else {