Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Database/Database.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2941,9 +2941,10 @@ public function updateDocument(string $collection, string $id, Document $documen
// Skip the nested documents as they will be checked later in recursions.
if (\array_key_exists($key, $relationships)) {
// No need to compare nested documents more than max depth.
if (count($this->relationshipWriteStack) >= Database::RELATION_MAX_DEPTH - 1) {
if (\count($this->relationshipWriteStack) >= Database::RELATION_MAX_DEPTH - 1) {
continue;
}

$relationType = (string) $relationships[$key]['options']['relationType'];
$side = (string) $relationships[$key]['options']['side'];

Expand DownExpand Up@@ -3043,7 +3044,7 @@ public function updateDocument(string $collection, string $id, Document $documen
$document = $this->silent(fn () => $this->updateDocumentRelationships($collection, $old, $document));
}

$this->adapter->updateDocument($collection->getId(), $document);
$document = $this->adapter->updateDocument($collection->getId(), $document);

if ($this->resolveRelationships) {
$document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document));
Expand DownExpand Up@@ -3074,13 +3075,17 @@ public function updateDocument(string $collection, string $id, Document $documen
*/
private function updateDocumentRelationships(Document $collection, Document $old, Document $document): Document
{
if ($collection->getId() === self::METADATA) {
return $document;
}

$attributes = $collection->getAttribute('attributes', []);

$relationships = \array_filter($attributes, function ($attribute) {
return $attribute['type'] === Database::VAR_RELATIONSHIP;
});

$stackCount = count($this->relationshipWriteStack);
$stackCount = \count($this->relationshipWriteStack);

foreach ($relationships as $index => $relationship) {
/** @var string $key */
Expand All@@ -3093,11 +3098,6 @@ private function updateDocumentRelationships(Document $collection, Document $old
$twoWayKey = (string) $relationship['options']['twoWayKey'];
$side = (string) $relationship['options']['side'];

if ($oldValue == $value) {
$document->removeAttribute($key);
continue;
}

if ($stackCount >= Database::RELATION_MAX_DEPTH - 1 && $this->relationshipWriteStack[$stackCount - 1] !== $relatedCollection->getId()) {
$document->removeAttribute($key);
continue;
Expand Down