diff --git a/composer.lock b/composer.lock index 2d1adac29..3f23d132d 100644 --- a/composer.lock +++ b/composer.lock @@ -2608,5 +2608,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 1e176b0c1..0c153b3e3 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -726,7 +726,7 @@ public function createDocument(string $collection, Document $document): Document try { $stmt->execute(); - $document['$internalId'] = $this->getDocument($collection, $document->getId())->getInternalId(); + $document['$internalId'] = $this->getDocument($collection, $document->getId(), [Query::select(['$internalId'])])->getInternalId(); if (isset($stmtPermissions)) { $stmtPermissions->execute(); diff --git a/tests/Database/Base.php b/tests/Database/Base.php index df210c2f4..d8ff11a5d 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -2008,6 +2008,31 @@ public function testFindByInternalID(array $data): void $this->assertEquals(1, count($documents)); } + /** + * @return void + * @throws \Utopia\Database\Exception + */ + public function testSelectInternalID(): void + { + $documents = static::getDatabase()->find('movies', [ + Query::select(['$internalId', '$id']), + Query::orderAsc(''), + Query::limit(1), + ]); + + $document = $documents[0]; + + $this->assertArrayHasKey('$internalId', $document); + $this->assertCount(2, $document); + + $document = static::getDatabase()->getDocument('movies', $document->getId(), [ + Query::select(['$internalId']), + ]); + + $this->assertArrayHasKey('$internalId', $document); + $this->assertCount(1, $document); + } + public function testFindOrderBy(): void { /**