From 656d4af49ed882fcf458ee802d6648f654a9aaac Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 8 Nov 2023 11:04:45 +0200 Subject: [PATCH 1/3] getId() on null --- src/Database/Database.php | 5 +++++ tests/Database/Base.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Database/Database.php b/src/Database/Database.php index 4ee1725db..8ddc7de20 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3880,6 +3880,8 @@ private function deleteDocumentRelationships(Document $collection, Document $doc $this->deleteRestrict($relatedCollection, $document, $value, $relationType, $twoWay, $twoWayKey, $side); break; case Database::RELATION_MUTATE_SET_NULL: + var_dump("inininininininininini RELATION_MUTATE_SET_NULL ninininininininininininininininin"); + var_dump($value); $this->deleteSetNull($collection, $relatedCollection, $document, $value, $relationType, $twoWay, $twoWayKey, $side); break; case Database::RELATION_MUTATE_CASCADE: @@ -4038,6 +4040,9 @@ private function deleteSetNull(Document $collection, Document $relatedCollection Query::equal($twoWayKey, [$document->getId()]) ]); } else { + if(empty($value)) { + return; + } $related = $this->getDocument($relatedCollection->getId(), $value->getId()); } diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 31b0dc9df..bc30b877d 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -5571,6 +5571,18 @@ public function testOneToOneTwoWayRelationship(): void onDelete: Database::RELATION_MUTATE_SET_NULL ); + + + $city1 = static::getDatabase()->getDocument('city', 'city1'); + var_dump($city1); + static::getDatabase()->updateDocument('city', 'city1', new Document(['newCountry' => null, '$id' => 'city1'])); + + // Check Delete TwoWay = TRUE with related value is NULL + $this->assertTrue(static::getDatabase()->deleteDocument('city', 'city1')); + // $this->assertTrue(false); + + + // Delete parent, will set child relationship to null for two-way static::getDatabase()->deleteDocument('country', 'country1'); From a2299ff52fffa93a9ba6fb1d458b4573df125e4f Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 8 Nov 2023 11:16:12 +0200 Subject: [PATCH 2/3] Remove comments --- phpunit.xml | 2 +- src/Database/Database.php | 2 -- tests/Database/Base.php | 13 +++++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 31b947dd6..3833748e0 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false"> + stopOnFailure="true"> ./tests/ diff --git a/src/Database/Database.php b/src/Database/Database.php index 8ddc7de20..f6bd3cdec 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3880,8 +3880,6 @@ private function deleteDocumentRelationships(Document $collection, Document $doc $this->deleteRestrict($relatedCollection, $document, $value, $relationType, $twoWay, $twoWayKey, $side); break; case Database::RELATION_MUTATE_SET_NULL: - var_dump("inininininininininini RELATION_MUTATE_SET_NULL ninininininininininininininininin"); - var_dump($value); $this->deleteSetNull($collection, $relatedCollection, $document, $value, $relationType, $twoWay, $twoWayKey, $side); break; case Database::RELATION_MUTATE_CASCADE: diff --git a/tests/Database/Base.php b/tests/Database/Base.php index bc30b877d..680f88112 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -5571,17 +5571,14 @@ public function testOneToOneTwoWayRelationship(): void onDelete: Database::RELATION_MUTATE_SET_NULL ); - - - $city1 = static::getDatabase()->getDocument('city', 'city1'); - var_dump($city1); static::getDatabase()->updateDocument('city', 'city1', new Document(['newCountry' => null, '$id' => 'city1'])); + $city1 = static::getDatabase()->getDocument('city', 'city1'); + $this->assertNull($city1->getAttribute('newCountry')); - // Check Delete TwoWay = TRUE with related value is NULL + // Check Delete TwoWay TRUE && RELATION_MUTATE_SET_NULL && related value NULL $this->assertTrue(static::getDatabase()->deleteDocument('city', 'city1')); - // $this->assertTrue(false); - - + $city1 = static::getDatabase()->getDocument('city', 'city1'); + $this->assertTrue($city1->isEmpty()); // Delete parent, will set child relationship to null for two-way static::getDatabase()->deleteDocument('country', 'country1'); From 4659cfbde303fba15d61cd19fb2b584175cfc663 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 8 Nov 2023 11:16:50 +0200 Subject: [PATCH 3/3] php unit --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 3833748e0..31b947dd6 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true"> + stopOnFailure="false"> ./tests/