From 91fc16015aaee03d35927028c8a6d8ee5fd232d4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 10 Mar 2026 16:49:45 +0200 Subject: [PATCH 1/3] nulls --- src/Database/Adapter/Mongo.php | 3 ++- src/Database/Database.php | 5 ++++- tests/e2e/Adapter/Scopes/DocumentTests.php | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Database/Adapter/Mongo.php b/src/Database/Adapter/Mongo.php index 52acc9541..159eec72a 100644 --- a/src/Database/Adapter/Mongo.php +++ b/src/Database/Adapter/Mongo.php @@ -1244,7 +1244,8 @@ public function createDocument(Document $collection, Document $document): Docume $record['_id'] = $sequence; } $options = $this->getTransactionOptions(); - $result = $this->insertDocument($name, $this->removeNullKeys($record), $options); + //$record = $this->removeNullKeys($record); + $result = $this->insertDocument($name, $record, $options); $result = $this->replaceChars('_', '$', $result); // in order to keep the original object refrence. foreach ($result as $key => $value) { diff --git a/src/Database/Database.php b/src/Database/Database.php index a76516b6f..c721fd973 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -5504,7 +5504,7 @@ public function createDocument(string $collection, Document $document): Document } $document = $this->encode($collection, $document); - +var_dump($document); if ($this->validate) { $validator = new Permissions(); if (!$validator->isValid($document->getPermissions())) { @@ -8653,6 +8653,8 @@ public function encode(Document $collection, Document $document, bool $applyDefa $filters = $attribute['filters'] ?? []; $value = $document->getAttribute($key); + //$offset = $document->offsetExists($key); + if (in_array($key, $internalDateAttributes) && is_string($value) && empty($value)) { $document->setAttribute($key, null); continue; @@ -8664,6 +8666,7 @@ public function encode(Document $collection, Document $document, bool $applyDefa // Continue on optional param with no default if (is_null($value) && is_null($default)) { + //$document->setAttribute($key, null); continue; } diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index e79e9ccec..4dc1dcb8e 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -232,6 +232,7 @@ public function testCreateDocument(): Document $this->assertEquals([], $manualIdDocument->getAttribute('empty')); $this->assertEquals('Works', $manualIdDocument->getAttribute('with-dash')); $this->assertEquals(null, $manualIdDocument->getAttribute('id')); + $this->assertTrue($manualIdDocument->offsetExists('id')); $manualIdDocument = $database->getDocument('documents', '56000'); @@ -257,6 +258,7 @@ public function testCreateDocument(): Document $this->assertEquals(['pink', 'green', 'blue'], $manualIdDocument->getAttribute('colors')); $this->assertEquals([], $manualIdDocument->getAttribute('empty')); $this->assertEquals('Works', $manualIdDocument->getAttribute('with-dash')); + $this->assertTrue($manualIdDocument->offsetExists('id')); try { $database->createDocument('documents', new Document([ @@ -345,10 +347,13 @@ public function testCreateDocument(): Document ])); $this->assertNotEmpty($documentIdNull->getSequence()); $this->assertNull($documentIdNull->getAttribute('id')); + $this->assertTrue($documentIdNull->offsetExists('id')); $documentIdNull = $database->getDocument('documents', $documentIdNull->getId()); + $this->assertNotEmpty($documentIdNull->getId()); $this->assertNull($documentIdNull->getAttribute('id')); + $this->assertTrue($documentIdNull->offsetExists('id')); $documentIdNull = $database->findOne('documents', [ query::isNull('id') From c20a925d933b2a651d62fa361742fdb7e0d070ca Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 10 Mar 2026 17:02:21 +0200 Subject: [PATCH 2/3] comments --- src/Database/Database.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index c721fd973..a76516b6f 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -5504,7 +5504,7 @@ public function createDocument(string $collection, Document $document): Document } $document = $this->encode($collection, $document); -var_dump($document); + if ($this->validate) { $validator = new Permissions(); if (!$validator->isValid($document->getPermissions())) { @@ -8653,8 +8653,6 @@ public function encode(Document $collection, Document $document, bool $applyDefa $filters = $attribute['filters'] ?? []; $value = $document->getAttribute($key); - //$offset = $document->offsetExists($key); - if (in_array($key, $internalDateAttributes) && is_string($value) && empty($value)) { $document->setAttribute($key, null); continue; @@ -8666,7 +8664,6 @@ public function encode(Document $collection, Document $document, bool $applyDefa // Continue on optional param with no default if (is_null($value) && is_null($default)) { - //$document->setAttribute($key, null); continue; } From 6c4943d50905d2594e31c02c19e13695a6fc2634 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 10 Mar 2026 17:05:14 +0200 Subject: [PATCH 3/3] test --- tests/e2e/Adapter/Scopes/DocumentTests.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 4dc1dcb8e..e51ccaf0b 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -231,8 +231,7 @@ public function testCreateDocument(): Document $this->assertEquals(['pink', 'green', 'blue'], $manualIdDocument->getAttribute('colors')); $this->assertEquals([], $manualIdDocument->getAttribute('empty')); $this->assertEquals('Works', $manualIdDocument->getAttribute('with-dash')); - $this->assertEquals(null, $manualIdDocument->getAttribute('id')); - $this->assertTrue($manualIdDocument->offsetExists('id')); + $this->assertEquals(null, $manualIdDocument->getAttribute('always_null')); $manualIdDocument = $database->getDocument('documents', '56000'); @@ -258,7 +257,6 @@ public function testCreateDocument(): Document $this->assertEquals(['pink', 'green', 'blue'], $manualIdDocument->getAttribute('colors')); $this->assertEquals([], $manualIdDocument->getAttribute('empty')); $this->assertEquals('Works', $manualIdDocument->getAttribute('with-dash')); - $this->assertTrue($manualIdDocument->offsetExists('id')); try { $database->createDocument('documents', new Document([ @@ -347,12 +345,14 @@ public function testCreateDocument(): Document ])); $this->assertNotEmpty($documentIdNull->getSequence()); $this->assertNull($documentIdNull->getAttribute('id')); + $this->assertNull($documentIdNull['id']); $this->assertTrue($documentIdNull->offsetExists('id')); $documentIdNull = $database->getDocument('documents', $documentIdNull->getId()); $this->assertNotEmpty($documentIdNull->getId()); $this->assertNull($documentIdNull->getAttribute('id')); + $this->assertNull($documentIdNull['id']); $this->assertTrue($documentIdNull->offsetExists('id')); $documentIdNull = $database->findOne('documents', [