From 7d2b9f3d81fd59bef0d6d5486801e715799d420f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 25 Jun 2025 12:31:01 +0530 Subject: [PATCH 1/4] added tenant to the result --- src/Database/Adapter/MariaDB.php | 1 + tests/e2e/Adapter/Scopes/DocumentTests.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index bab2eb267..e84514f95 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1661,6 +1661,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, } if (\array_key_exists('_tenant', $document)) { $document['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; + $results[$index]['$tenant'] = $document['$tenant']; unset($results[$index]['_tenant']); } if (\array_key_exists('_createdAt', $document)) { diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 3fdbb87d7..4e4ccbb7e 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -4245,6 +4245,14 @@ public function testEmptyTenant(): void $database = static::getDatabase(); if ($database->getAdapter()->getSharedTables()) { + $documents = $database->find( + 'documents', + [Query::select(['*'])] // Mongo bug with Integer UID + ); + + $document = $documents[0]; + $doc = $database->getDocument($document->getCollection(), $document->getId()); + $this->assertEquals($document->getTenant(), $doc->getTenant()); $this->expectNotToPerformAssertions(); return; } From 6f1646b9834eeac93389991a11177148a78ee216 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 25 Jun 2025 12:35:15 +0530 Subject: [PATCH 2/4] updated tenant in find for postgres --- src/Database/Adapter/Postgres.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index 37d2edeec..ef6439495 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -1546,6 +1546,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, } if (\array_key_exists('_tenant', $document)) { $document['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; + $results[$index]['$tenant'] = $document['$tenant']; unset($results[$index]['_tenant']); } if (\array_key_exists('_createdAt', $document)) { From ac70b5b0238a89ca883d934fd0f44770b4ca5dd5 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 25 Jun 2025 12:36:26 +0530 Subject: [PATCH 3/4] removed no assertion from the document tests in tenant empty in shared table --- tests/e2e/Adapter/Scopes/DocumentTests.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 4e4ccbb7e..b4969242a 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -4253,7 +4253,6 @@ public function testEmptyTenant(): void $document = $documents[0]; $doc = $database->getDocument($document->getCollection(), $document->getId()); $this->assertEquals($document->getTenant(), $doc->getTenant()); - $this->expectNotToPerformAssertions(); return; } From 43aa35c3d7150b19485903f07256f533fc6051c4 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 25 Jun 2025 12:42:00 +0530 Subject: [PATCH 4/4] removed setting tenant from document --- src/Database/Adapter/MariaDB.php | 3 +-- src/Database/Adapter/Postgres.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index e84514f95..b08b160d3 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1660,8 +1660,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, unset($results[$index]['_id']); } if (\array_key_exists('_tenant', $document)) { - $document['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; - $results[$index]['$tenant'] = $document['$tenant']; + $results[$index]['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; unset($results[$index]['_tenant']); } if (\array_key_exists('_createdAt', $document)) { diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index ef6439495..319f05058 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -1545,8 +1545,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, unset($results[$index]['_id']); } if (\array_key_exists('_tenant', $document)) { - $document['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; - $results[$index]['$tenant'] = $document['$tenant']; + $results[$index]['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant']; unset($results[$index]['_tenant']); } if (\array_key_exists('_createdAt', $document)) {