Skip to content

Commit 3407cd0

Browse files
authored
Merge pull request #314 from utopia-php/fix-create-documents-use-internal-id
copy internalId when running createDocuments
2 parents b9f62a9 + 54dac44 commit 3407cd0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ public function createDocuments(string $collection, array $documents, int $batch
585585
$attributes['_createdAt'] = $document->getCreatedAt();
586586
$attributes['_updatedAt'] = $document->getUpdatedAt();
587587
$attributes['_permissions'] = \json_encode($document->getPermissions());
588+
if(!empty($document->getInternalId())) {
589+
$attributes['_id'] = $document->getInternalId();
590+
}
588591

589592
$columns = [];
590593
foreach (\array_keys($attributes) as $key => $attribute) {

src/Database/Adapter/Mongo/MongoDBAdapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ public function createDocuments(string $collection, array $documents, int $batch
397397

398398
$records = [];
399399
foreach ($documents as $document) {
400+
if(!empty($document->getInternalId())) {
401+
$document->setAttribute('_id', $document->getInternalId());
402+
}
400403
$document->removeAttribute('$internalId');
401404

402405
$records[] = $this->replaceChars('$', '_', (array)$document);

0 commit comments

Comments
 (0)