Skip to content

Commit

Permalink
Merge pull request #314 from utopia-php/fix-create-documents-use-inte…
Browse files Browse the repository at this point in the history
…rnal-id

copy internalId when running createDocuments
  • Loading branch information
abnegate authored Oct 24, 2023
2 parents b9f62a9 + 54dac44 commit 3407cd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ public function createDocuments(string $collection, array $documents, int $batch
$attributes['_createdAt'] = $document->getCreatedAt();
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = \json_encode($document->getPermissions());
if(!empty($document->getInternalId())) {
$attributes['_id'] = $document->getInternalId();
}

$columns = [];
foreach (\array_keys($attributes) as $key => $attribute) {
Expand Down
3 changes: 3 additions & 0 deletions src/Database/Adapter/Mongo/MongoDBAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ public function createDocuments(string $collection, array $documents, int $batch

$records = [];
foreach ($documents as $document) {
if(!empty($document->getInternalId())) {
$document->setAttribute('_id', $document->getInternalId());
}
$document->removeAttribute('$internalId');

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

0 comments on commit 3407cd0

Please sign in to comment.