From 30a38c0c8ca2996bf4bc8cfdb7de97dc32264b83 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 5 Nov 2023 19:53:50 +0200 Subject: [PATCH] Reproduce Many to One issue --- phpunit.xml | 2 +- src/Database/Database.php | 4 ++++ tests/Database/Base.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) 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 d8393ac8f..14f6e82bf 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3550,6 +3550,10 @@ private function updateDocumentRelationships(Document $collection, Document $old $document->setAttribute($key, $value->getId()); } elseif (\is_null($value)) { break; + } elseif(empty($value)){ + var_dump('I am an empty array Is I think it is ok to throw an exeption'); + throw new DatabaseException('Invalid value for relationship'); + } else { throw new DatabaseException('Invalid value for relationship'); } diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 31b0dc9df..4ec3f8566 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -6799,6 +6799,24 @@ public function testManyToOneOneWayRelationship(): void $review5 = static::getDatabase()->getDocument('review', 'review5'); $this->assertEquals('Movie 5', $review5->getAttribute('movie')->getAttribute('name')); + + // Todo: fix this is failing + static::getDatabase()->updateDocument('review', $review5->getId(), new Document([ + '$id' => 'review5', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Review 5', + 'movie' => [], // + ])); + + + $this->assertEquals(true, false); + + + // Update document with new related document static::getDatabase()->updateDocument( 'review',