From 3143223b8aa208b9f5f2aea21bd76b1e446dc8bc Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 27 Jul 2023 00:54:20 +0530 Subject: [PATCH 1/7] fixes non existing documents bug in one to one, one to many and many to many relationships --- src/Database/Database.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index c90d68c6b..13ac86c1e 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -2995,7 +2995,14 @@ private function updateDocumentRelationships(Document $collection, Document $old switch ($relationType) { case Database::RELATION_ONE_TO_ONE: if (!$twoWay) { - if ($value instanceof Document) { + if (\is_string($value)) { + $related = $this->getDocument($relatedCollection->getId(), $value); + if ($related->isEmpty()) { + //If no such document exists in related collection + //For one-one we need to update the related key to old value, either null if no relation exists or old related document id + $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + } + } elseif ($value instanceof Document) { $relationId = $this->relateDocuments( $collection, $relatedCollection, @@ -3133,6 +3140,10 @@ private function updateDocumentRelationships(Document $collection, Document $old $this->getDocument($relatedCollection->getId(), $relation) ); + if ($related->isEmpty()) { + continue; + } + $this->skipRelationships(fn () => $this->updateDocument( $relatedCollection->getId(), $related->getId(), @@ -3233,7 +3244,7 @@ private function updateDocumentRelationships(Document $collection, Document $old foreach ($value as $relation) { if (\is_string($relation)) { - if (\in_array($relation, $oldIds)) { + if (\in_array($relation, $oldIds) || $this->getDocument($relatedCollection->getId(), $relation)->isEmpty()) { continue; } } elseif ($relation instanceof Document) { From dd91c20b0397164fb87469d6ee77e59507ddf209 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 27 Jul 2023 20:55:56 +0530 Subject: [PATCH 2/7] fixes another case in many to one relationship and adds test case for all scenarios --- src/Database/Database.php | 6 ++ tests/Database/Base.php | 132 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/src/Database/Database.php b/src/Database/Database.php index 13ac86c1e..1db72f901 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3177,6 +3177,12 @@ private function updateDocumentRelationships(Document $collection, Document $old } if (\is_string($value)) { + $related = $this->getDocument($relatedCollection->getId(), $value); + if ($related->isEmpty()) { + //If no such document exists in related collection + //For one-one we need to update the related key to old value, either null if no relation exists or old related document id + $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + } $this->deleteCachedDocument($relatedCollection->getId(), $value); } elseif ($value instanceof Document) { $related = $this->getDocument($relatedCollection->getId(), $value->getId()); diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 8a83b39ba..85599ceec 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4095,6 +4095,23 @@ public function testOneToOneOneWayRelationship(): void ], ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('person', 'person1', new Document([ + '$id' => 'person1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Person 1', + '$collection' => 'person', + 'library' => 'no-library' + ])); + + $person1Document = static::getDatabase()->getDocument('person', 'person1'); + // Assert document does not contain non existing relation document. + $this->assertEquals('library1', $person1Document->getAttribute('library')->getAttribute('$id')); + // Update through create $library10 = static::getDatabase()->createDocument('library', new Document([ '$id' => 'library10', @@ -5135,6 +5152,26 @@ public function testOneToManyOneWayRelationship(): void ], ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('artist', 'artist1', new Document([ + '$id' => 'artist1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Artist 1', + '$collection' => 'artist', + 'albums' => [ + 'album1', + 'no-album' + ] + ])); + + $artist1Document = static::getDatabase()->getDocument('artist', 'artist1'); + // Assert document does not contain non existing relation document. + $this->assertEquals(1, \count($artist1Document->getAttribute('albums'))); + // Create document with relationship with related ID static::getDatabase()->createDocument('album', new Document([ '$id' => 'album2', @@ -5513,6 +5550,27 @@ public function testOneToManyTwoWayRelationship(): void ], ], ])); + + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('customer', 'customer1', new Document([ + '$id' => 'customer1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Customer 1', + '$collection' => 'customer', + 'accounts' => [ + 'account1', + 'no-account' + ] + ])); + + $customer1Document = static::getDatabase()->getDocument('customer', 'customer1'); + // Assert document does not contain non existing relation document. + $this->assertEquals(1, \count($customer1Document->getAttribute('accounts'))); + // Create document with relationship with related ID $account2 = static::getDatabase()->createDocument('account', new Document([ '$id' => 'account2', @@ -5954,6 +6012,23 @@ public function testManyToOneOneWayRelationship(): void ], ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('review', 'review1', new Document([ + '$id' => 'review1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Review 1', + '$collection' => 'review', + 'movie' => 'no-movie' + ])); + + $review1Document = static::getDatabase()->getDocument('review', 'review1'); + // Assert document does not contain non existing relation document. + $this->assertEquals('movie1', $review1Document->getAttribute('movie')->getAttribute('$id')); + // Create document with relationship to existing document by ID $review10 = static::getDatabase()->createDocument('review', new Document([ '$id' => 'review10', @@ -6281,6 +6356,23 @@ public function testManyToOneTwoWayRelationship(): void ], ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('product', 'product1', new Document([ + '$id' => 'product1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Product 1', + '$collection' => 'product', + 'store' => 'no-store' + ])); + + $product1Document = static::getDatabase()->getDocument('product', 'product1'); + // Assert document does not contain non existing relation document. + $this->assertEquals('store1', $product1Document->getAttribute('store')->getAttribute('$id')); + // Create document with relationship with related ID static::getDatabase()->createDocument('store', new Document([ '$id' => 'store2', @@ -6741,6 +6833,26 @@ public function testManyToManyOneWayRelationship(): void ] ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('playlist', 'playlist1', new Document([ + '$id' => 'playlist1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Playlist 1', + '$collection' => 'playlist', + 'songs' => [ + 'song1', + 'no-song' + ] + ])); + + $playlist1Document = static::getDatabase()->getDocument('playlist', 'playlist1'); + // Assert document does not contain non existing relation document. + $this->assertEquals(1, \count($playlist1Document->getAttribute('songs'))); + $documents = static::getDatabase()->find('playlist', [ Query::select(['name']), Query::limit(1) @@ -7032,6 +7144,26 @@ public function testManyToManyTwoWayRelationship(): void ], ])); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('students', 'student1', new Document([ + '$id' => 'student1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'Student 1', + '$collection' => 'students', + 'classes' => [ + 'class1', + 'no-class' + ] + ])); + + $student1Document = static::getDatabase()->getDocument('students', 'student1'); + // Assert document does not contain non existing relation document. + $this->assertEquals(1, \count($student1Document->getAttribute('classes'))); + // Create document with relationship with related ID static::getDatabase()->createDocument('classes', new Document([ '$id' => 'class2', From b604cac6d52a9dc5d5c4f1aeaa904df6576fb51e Mon Sep 17 00:00:00 2001 From: Prateek Banga <30731059+fanatic75@users.noreply.github.com> Date: Fri, 28 Jul 2023 03:49:08 +0530 Subject: [PATCH 3/7] Updates comment formatting to consistent style Co-authored-by: Steven <1477010+stnguyen90@users.noreply.github.com> --- src/Database/Database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 1db72f901..038b47e44 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -2998,8 +2998,8 @@ private function updateDocumentRelationships(Document $collection, Document $old if (\is_string($value)) { $related = $this->getDocument($relatedCollection->getId(), $value); if ($related->isEmpty()) { - //If no such document exists in related collection - //For one-one we need to update the related key to old value, either null if no relation exists or old related document id + // If no such document exists in related collection + // For one-one we need to update the related key to old value, either null if no relation exists or old related document id $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); } } elseif ($value instanceof Document) { From 297359377d8cc9d93a60c400c7e2af7ed2ac8507 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Wed, 2 Aug 2023 17:29:39 +0530 Subject: [PATCH 4/7] add non existing doc check in one-to-one two-way Previously we were getting 500 as the non existing doc needs to be updated in two-way relationship type and non existing doc does not have key. Now we are keeping it consistent with other relationship types and skipping non existing doc --- src/Database/Database.php | 7 ++++++- tests/Database/Base.php | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 038b47e44..b033f6ba3 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3022,7 +3022,12 @@ private function updateDocumentRelationships(Document $collection, Document $old switch (\gettype($value)) { case 'string': $related = $this->skipRelationships(fn () => $this->getDocument($relatedCollection->getId(), $value)); - + if ($related->isEmpty()) { + // If no such document exists in related collection + // For one-one we need to update the related key to old value, either null if no relation exists or old related document id + $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + break; + } if ( $oldValue?->getId() !== $value && $this->skipRelationships(fn () => $this->findOne($relatedCollection->getId(), [ diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 85599ceec..d31bfc193 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4527,6 +4527,23 @@ public function testOneToOneTwoWayRelationship(): void $country1 = static::getDatabase()->getDocument('country', 'country1'); $this->assertEquals('London', $country1->getAttribute('city')->getAttribute('name')); + // Update a document with non existing related document. It should not get added to the list. + static::getDatabase()->updateDocument('country', 'country1', new Document([ + '$id' => 'country1', + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'name' => 'England', + '$collection' => 'country', + 'city' => 'no-city' + ])); + + $country1Document = static::getDatabase()->getDocument('country', 'country1'); + // Assert document does not contain non existing relation document. + $this->assertEquals('city1', $country1Document->getAttribute('city')->getAttribute('$id')); + try { static::getDatabase()->deleteDocument('country', 'country1'); $this->fail('Failed to throw exception'); From 29d4e5c48f70066c00000f52178479690146e089 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 8 Aug 2023 21:23:57 +0530 Subject: [PATCH 5/7] set null when related doc not found in one to one and many to one --- src/Database/Database.php | 14 ++--- tests/Database/Base.php | 120 +++++--------------------------------- 2 files changed, 23 insertions(+), 111 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index b033f6ba3..3f1771809 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -2999,8 +2999,8 @@ private function updateDocumentRelationships(Document $collection, Document $old $related = $this->getDocument($relatedCollection->getId(), $value); if ($related->isEmpty()) { // If no such document exists in related collection - // For one-one we need to update the related key to old value, either null if no relation exists or old related document id - $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + // For one-one we need to update the related key to null if no relation exists + $document->setAttribute($key, null); } } elseif ($value instanceof Document) { $relationId = $this->relateDocuments( @@ -3024,8 +3024,8 @@ private function updateDocumentRelationships(Document $collection, Document $old $related = $this->skipRelationships(fn () => $this->getDocument($relatedCollection->getId(), $value)); if ($related->isEmpty()) { // If no such document exists in related collection - // For one-one we need to update the related key to old value, either null if no relation exists or old related document id - $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + // For one-one we need to update the related key to null if no relation exists + $document->setAttribute($key, null); break; } if ( @@ -3184,9 +3184,9 @@ private function updateDocumentRelationships(Document $collection, Document $old if (\is_string($value)) { $related = $this->getDocument($relatedCollection->getId(), $value); if ($related->isEmpty()) { - //If no such document exists in related collection - //For one-one we need to update the related key to old value, either null if no relation exists or old related document id - $document->setAttribute($key, ($oldValue instanceof Document && !($oldValue->isEmpty()) ? $oldValue->getId() : null)); + // If no such document exists in related collection + // For many-one we need to update the related key to null if no relation exists + $document->setAttribute($key, null); } $this->deleteCachedDocument($relatedCollection->getId(), $value); } elseif ($value instanceof Document) { diff --git a/tests/Database/Base.php b/tests/Database/Base.php index d31bfc193..22e35d465 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4096,21 +4096,15 @@ public function testOneToOneOneWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('person', 'person1', new Document([ - '$id' => 'person1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Person 1', - '$collection' => 'person', - 'library' => 'no-library' - ])); + static::getDatabase()->updateDocument( + 'person', + 'person1', + $person1->setAttribute('library', 'no-library') + ); $person1Document = static::getDatabase()->getDocument('person', 'person1'); // Assert document does not contain non existing relation document. - $this->assertEquals('library1', $person1Document->getAttribute('library')->getAttribute('$id')); + $this->assertEquals('null', $person1Document->getAttribute('library')); // Update through create $library10 = static::getDatabase()->createDocument('library', new Document([ @@ -4528,21 +4522,11 @@ public function testOneToOneTwoWayRelationship(): void $this->assertEquals('London', $country1->getAttribute('city')->getAttribute('name')); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('country', 'country1', new Document([ - '$id' => 'country1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'England', - '$collection' => 'country', - 'city' => 'no-city' - ])); + static::getDatabase()->updateDocument('country', 'country1', $country1->setAttribute('city', 'no-city')); $country1Document = static::getDatabase()->getDocument('country', 'country1'); // Assert document does not contain non existing relation document. - $this->assertEquals('city1', $country1Document->getAttribute('city')->getAttribute('$id')); + $this->assertEquals('null', $country1Document->getAttribute('city')); try { static::getDatabase()->deleteDocument('country', 'country1'); @@ -5170,20 +5154,7 @@ public function testOneToManyOneWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('artist', 'artist1', new Document([ - '$id' => 'artist1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Artist 1', - '$collection' => 'artist', - 'albums' => [ - 'album1', - 'no-album' - ] - ])); + static::getDatabase()->updateDocument('artist', 'artist1', $artist1->setAttribute('albums', ['album1, no-album'])); $artist1Document = static::getDatabase()->getDocument('artist', 'artist1'); // Assert document does not contain non existing relation document. @@ -5569,20 +5540,7 @@ public function testOneToManyTwoWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('customer', 'customer1', new Document([ - '$id' => 'customer1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Customer 1', - '$collection' => 'customer', - 'accounts' => [ - 'account1', - 'no-account' - ] - ])); + static::getDatabase()->updateDocument('customer', 'customer1', $customer1->setAttribute('accounts', ['account1','no-account'])); $customer1Document = static::getDatabase()->getDocument('customer', 'customer1'); // Assert document does not contain non existing relation document. @@ -6030,21 +5988,11 @@ public function testManyToOneOneWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('review', 'review1', new Document([ - '$id' => 'review1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Review 1', - '$collection' => 'review', - 'movie' => 'no-movie' - ])); + static::getDatabase()->updateDocument('review', 'review1', $review1->setAttribute('movie', 'no-movie')); $review1Document = static::getDatabase()->getDocument('review', 'review1'); // Assert document does not contain non existing relation document. - $this->assertEquals('movie1', $review1Document->getAttribute('movie')->getAttribute('$id')); + $this->assertEquals('null', $review1Document->getAttribute('movie')); // Create document with relationship to existing document by ID $review10 = static::getDatabase()->createDocument('review', new Document([ @@ -6374,21 +6322,11 @@ public function testManyToOneTwoWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('product', 'product1', new Document([ - '$id' => 'product1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Product 1', - '$collection' => 'product', - 'store' => 'no-store' - ])); + static::getDatabase()->updateDocument('product', 'product1', $product1->setAttribute('store', 'no-store')); $product1Document = static::getDatabase()->getDocument('product', 'product1'); // Assert document does not contain non existing relation document. - $this->assertEquals('store1', $product1Document->getAttribute('store')->getAttribute('$id')); + $this->assertEquals('null', $product1Document->getAttribute('store')); // Create document with relationship with related ID static::getDatabase()->createDocument('store', new Document([ @@ -6851,20 +6789,7 @@ public function testManyToManyOneWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('playlist', 'playlist1', new Document([ - '$id' => 'playlist1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Playlist 1', - '$collection' => 'playlist', - 'songs' => [ - 'song1', - 'no-song' - ] - ])); + static::getDatabase()->updateDocument('playlist', 'playlist1', $playlist1->setAttribute('songs', ['song1','no-song'])); $playlist1Document = static::getDatabase()->getDocument('playlist', 'playlist1'); // Assert document does not contain non existing relation document. @@ -7162,20 +7087,7 @@ public function testManyToManyTwoWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('students', 'student1', new Document([ - '$id' => 'student1', - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'name' => 'Student 1', - '$collection' => 'students', - 'classes' => [ - 'class1', - 'no-class' - ] - ])); + static::getDatabase()->updateDocument('students', 'student1', $student1->setAttribute('classes', ['class1', 'no-class'])); $student1Document = static::getDatabase()->getDocument('students', 'student1'); // Assert document does not contain non existing relation document. From 6ed5fb66244b27c05feaa9a360dc114f4dcbf01a Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 8 Aug 2023 21:26:43 +0530 Subject: [PATCH 6/7] lint fix --- tests/Database/Base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 22e35d465..05cc5ea68 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4097,9 +4097,9 @@ public function testOneToOneOneWayRelationship(): void // Update a document with non existing related document. It should not get added to the list. static::getDatabase()->updateDocument( - 'person', - 'person1', - $person1->setAttribute('library', 'no-library') + 'person', + 'person1', + $person1->setAttribute('library', 'no-library') ); $person1Document = static::getDatabase()->getDocument('person', 'person1'); From 1188e782dd9dc8f5063f8d200fa10f5d8228656f Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 8 Aug 2023 23:18:57 +0530 Subject: [PATCH 7/7] fix tests --- tests/Database/Base.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 05cc5ea68..1b3d5ee77 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4104,7 +4104,13 @@ public function testOneToOneOneWayRelationship(): void $person1Document = static::getDatabase()->getDocument('person', 'person1'); // Assert document does not contain non existing relation document. - $this->assertEquals('null', $person1Document->getAttribute('library')); + $this->assertEquals(null, $person1Document->getAttribute('library')); + + static::getDatabase()->updateDocument( + 'person', + 'person1', + $person1->setAttribute('library', 'library1') + ); // Update through create $library10 = static::getDatabase()->createDocument('library', new Document([ @@ -4522,12 +4528,12 @@ public function testOneToOneTwoWayRelationship(): void $this->assertEquals('London', $country1->getAttribute('city')->getAttribute('name')); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('country', 'country1', $country1->setAttribute('city', 'no-city')); + static::getDatabase()->updateDocument('country', 'country1', $doc->setAttribute('city', 'no-city')); $country1Document = static::getDatabase()->getDocument('country', 'country1'); // Assert document does not contain non existing relation document. - $this->assertEquals('null', $country1Document->getAttribute('city')); - + $this->assertEquals(null, $country1Document->getAttribute('city')); + static::getDatabase()->updateDocument('country', 'country1', $doc->setAttribute('city', 'city1')); try { static::getDatabase()->deleteDocument('country', 'country1'); $this->fail('Failed to throw exception'); @@ -5154,7 +5160,7 @@ public function testOneToManyOneWayRelationship(): void ])); // Update a document with non existing related document. It should not get added to the list. - static::getDatabase()->updateDocument('artist', 'artist1', $artist1->setAttribute('albums', ['album1, no-album'])); + static::getDatabase()->updateDocument('artist', 'artist1', $artist1->setAttribute('albums', ['album1', 'no-album'])); $artist1Document = static::getDatabase()->getDocument('artist', 'artist1'); // Assert document does not contain non existing relation document. @@ -5992,7 +5998,9 @@ public function testManyToOneOneWayRelationship(): void $review1Document = static::getDatabase()->getDocument('review', 'review1'); // Assert document does not contain non existing relation document. - $this->assertEquals('null', $review1Document->getAttribute('movie')); + $this->assertEquals(null, $review1Document->getAttribute('movie')); + + static::getDatabase()->updateDocument('review', 'review1', $review1->setAttribute('movie', 'movie1')); // Create document with relationship to existing document by ID $review10 = static::getDatabase()->createDocument('review', new Document([ @@ -6326,7 +6334,9 @@ public function testManyToOneTwoWayRelationship(): void $product1Document = static::getDatabase()->getDocument('product', 'product1'); // Assert document does not contain non existing relation document. - $this->assertEquals('null', $product1Document->getAttribute('store')); + $this->assertEquals(null, $product1Document->getAttribute('store')); + + static::getDatabase()->updateDocument('product', 'product1', $product1->setAttribute('store', 'store1')); // Create document with relationship with related ID static::getDatabase()->createDocument('store', new Document([