From 6d5d60e351125123bc73b445d2fca0a5eb99b82e Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 12 Jun 2025 11:00:25 +0300 Subject: [PATCH 01/10] Check internals --- src/Database/Adapter/SQL.php | 37 ++++++++++------------ src/Database/Database.php | 34 ++++++++++++++++++++ src/Database/Document.php | 7 +--- tests/e2e/Adapter/Scopes/DocumentTests.php | 3 +- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index c3427ae83..9b47d8d8e 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -350,6 +350,10 @@ public function getDocument(string $collection, string $id, array $queries = [], $sql .= " {$forUpdate}"; } + if (!empty($selections)){ + echo $sql.PHP_EOL; + } + $stmt = $this->getPDO()->prepare($sql); $stmt->bindValue(':_uid', $id); @@ -1677,35 +1681,26 @@ public function getTenantQuery( /** * Get the SQL projection given the selected attributes * - * @param array $selects + * @param array $selects * @return string * @throws Exception */ protected function addHiddenAttribute(array $selects): string { - $hash = [Query::DEFAULT_ALIAS => true]; - - foreach ($selects as $select) { - $alias = $select->getAlias(); - if (!isset($hash[$alias])){ - $hash[$alias] = true; - } - } + //return ''; - $hash = array_keys($hash); + $alias = Query::DEFAULT_ALIAS; $strings = []; - foreach ($hash as $alias) { - $strings[] = $alias.'._uid as '.$this->quote($alias.'::$id'); - $strings[] = $alias.'._id as '.$this->quote($alias.'::$internalId'); - $strings[] = $alias.'._permissions as '.$this->quote($alias.'::$permissions'); - $strings[] = $alias.'._createdAt as '.$this->quote($alias.'::$createdAt'); - $strings[] = $alias.'._updatedAt as '.$this->quote($alias.'::$updatedAt'); + $strings[] = $alias.'._uid as '.$this->quote($alias.'::$id'); + $strings[] = $alias.'._id as '.$this->quote($alias.'::$sequence'); + $strings[] = $alias.'._permissions as '.$this->quote($alias.'::$permissions'); + $strings[] = $alias.'._createdAt as '.$this->quote($alias.'::$createdAt'); + $strings[] = $alias.'._updatedAt as '.$this->quote($alias.'::$updatedAt'); - if ($this->sharedTables) { - $strings[] = $alias.'._tenant as '.$this->quote($alias.'::$tenant'); - } + if ($this->sharedTables) { + $strings[] = $alias.'._tenant as '.$this->quote($alias.'::$tenant'); } return ', '.implode(', ', $strings); @@ -1722,7 +1717,7 @@ protected function addHiddenAttribute(array $selects): string protected function getAttributeProjection(array $selections, string $prefix): mixed { if (empty($selections) || \in_array('*', $selections)) { - return "{$this->quote($prefix)}.*"; + return "{$this->quote($prefix)}.* {$this->addHiddenAttribute($selections)}"; } $internalKeys = [ @@ -1743,7 +1738,7 @@ protected function getAttributeProjection(array $selections, string $prefix): mi $selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}"; } - return \implode(',', $selections); + return \implode(',', $selections).$this->addHiddenAttribute($selections); } protected function getInternalKeyForAttribute(string $attribute): string diff --git a/src/Database/Database.php b/src/Database/Database.php index 6ed45aa99..b1a197d89 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -526,6 +526,25 @@ public function silent(callable $callback, ?array $listeners = null): mixed } } + /** + * Check if attribute is internal + * + * @param string $attribute + * @return bool + */ + public static function isInternalAttribute(string $attribute): bool + { + if (str_contains($attribute, '$')) { + foreach (Database::INTERNAL_ATTRIBUTES as $attr) { + if (str_contains($attribute, $attr['$id'])) { + return true; + } + } + } + + return false; + } + /** * Get getConnection Id * @@ -6298,6 +6317,21 @@ public static function addFilter(string $name, callable $encode, callable $decod */ public function encode(Document $collection, Document $document): Document { + /** + * When iterating over an ArrayObject, foreach uses an internal iterator (like Iterator), and modifying the object during iteration doesn’t affect the iterator immediately. + */ + $keysToRemove = []; + + foreach ($document as $key => $value) { + if (strpos($key, '::$') !== false) { + $keysToRemove[] = $key; + } + } + + foreach ($keysToRemove as $key) { + unset($document[$key]); + } + $attributes = $collection->getAttribute('attributes', []); $internalAttributes = \array_filter(Database::INTERNAL_ATTRIBUTES, function ($attribute) { diff --git a/src/Database/Document.php b/src/Database/Document.php index 2ed634f46..65c034013 100644 --- a/src/Database/Document.php +++ b/src/Database/Document.php @@ -183,13 +183,8 @@ public function getAttributes(): array { $attributes = []; - $internalKeys = \array_map( - fn ($attr) => $attr['$id'], - Database::INTERNAL_ATTRIBUTES - ); - foreach ($this as $attribute => $value) { - if (\in_array($attribute, $internalKeys)) { + if (Database::isInternalAttribute($attribute)){ continue; } diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 3fdbb87d7..562b9ebc6 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -741,8 +741,9 @@ public function testUpsertDocumentsAttributeMismatch(): void $newDocument ->setAttribute('last', 'last') ]); - +var_dump($docs); $this->assertEquals(1, $docs); + $this->assertEquals('first', $existingDocument->getAttribute('first')); $this->assertEquals(null, $existingDocument->getAttribute('last')); $this->assertEquals('second', $newDocument->getAttribute('first')); From 173264b47af77b6af2973b2b41f5199b91f1182e Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 12 Jun 2025 13:36:08 +0300 Subject: [PATCH 02/10] RelationshipTests --- tests/e2e/Adapter/Scopes/RelationshipTests.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/e2e/Adapter/Scopes/RelationshipTests.php b/tests/e2e/Adapter/Scopes/RelationshipTests.php index f7623db49..fa5eb888f 100644 --- a/tests/e2e/Adapter/Scopes/RelationshipTests.php +++ b/tests/e2e/Adapter/Scopes/RelationshipTests.php @@ -749,6 +749,10 @@ public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void ], ], ])); + +var_dump($level1); + //$level1 = $database->getDocument('level1', $level1->getId()); + $database->updateDocument('level1', $level1->getId(), new Document($level1->getArrayCopy())); $updatedLevel1 = $database->getDocument('level1', $level1->getId()); $this->assertEquals($level1, $updatedLevel1); @@ -898,6 +902,9 @@ public function testNoInvalidKeysWithRelationships(): void ] ] ])); + + //$species = $database->getDocument('species', $species->getId()); + $database->updateDocument('species', $species->getId(), new Document([ '$id' => ID::custom('1'), '$collection' => 'species', From 1d4d7d188909f4f79a8aa080286b0883dcfd8816 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 15 Jun 2025 14:26:57 +0300 Subject: [PATCH 03/10] Add attribute for update and create --- src/Database/Adapter/SQL.php | 21 +++++------ src/Database/Database.php | 36 +++++++++++++++++-- src/Database/Document.php | 12 +++---- .../e2e/Adapter/Scopes/RelationshipTests.php | 2 ++ 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 9b47d8d8e..8f86baaa3 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -397,6 +397,12 @@ public function getDocument(string $collection, string $id, array $queries = [], unset($document['_permissions']); } + $document['main::$permissions'] = json_decode($document['main::$permissions'], true); + + if ($this->sharedTables) { + $document['main::$tenant'] = $document['main::$tenant'] === null ? null : (int)$document['main::$tenant']; + } + return new Document($document); } @@ -1720,21 +1726,10 @@ protected function getAttributeProjection(array $selections, string $prefix): mi return "{$this->quote($prefix)}.* {$this->addHiddenAttribute($selections)}"; } - $internalKeys = [ - '$id', - '$sequence', - '$permissions', - '$createdAt', - '$updatedAt', - ]; - - $selections = \array_diff($selections, [...$internalKeys, '$collection']); - - foreach ($internalKeys as $internalKey) { - $selections[] = $this->getInternalKeyForAttribute($internalKey); - } + $selections = array_diff($selections, ['$collection']); foreach ($selections as &$selection) { + $selection = $this->getInternalKeyForAttribute($selection); $selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}"; } diff --git a/src/Database/Database.php b/src/Database/Database.php index b1a197d89..d54811676 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3296,7 +3296,7 @@ public function getDocument(string $collection, string $id, array $queries = [], if ($collection->getId() !== self::METADATA) { if (!$validator->isValid([ ...$collection->getRead(), - ...($documentSecurity ? $document->getRead() : []) + ...($documentSecurity ? $document->getRead('main::$permissions') : []) ])) { return new Document(); } @@ -3323,7 +3323,7 @@ public function getDocument(string $collection, string $id, array $queries = [], if ($collection->getId() !== self::METADATA) { if (!$validator->isValid([ ...$collection->getRead(), - ...($documentSecurity ? $document->getRead() : []) + ...($documentSecurity ? $document->getRead('main::$permissions') : []) ])) { return new Document(); } @@ -3686,6 +3686,13 @@ public function createDocument(string $collection, Document $document): Document $this->trigger(self::EVENT_DOCUMENT_CREATE, $document); + $document->setAttribute('main::$id', $document->getId()); + $document->setAttribute('main::$sequence', $document->getSequence()); + $document->setAttribute('main::$permissions', $document->getPermissions()); + $document->setAttribute('main::$createdAt', $document->getCreatedAt()); + $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); + $document->setAttribute('main::$tenant', $document->getTenant()); + return $document; } @@ -4133,6 +4140,10 @@ public function updateDocument(string $collection, string $id, Document $documen $document = $this->withTransaction(function () use ($collection, $id, $document) { $time = DateTime::now(); + + /** + * @var $old Document + */ $old = Authorization::skip(fn () => $this->silent( fn () => $this->getDocument($collection->getId(), $id, forUpdate: true) )); @@ -4162,8 +4173,14 @@ public function updateDocument(string $collection, string $id, Document $documen $relationships[$relationship->getAttribute('key')] = $relationship; } + $alias = Query::DEFAULT_ALIAS; + // Compare if the document has any changes foreach ($document as $key => $value) { + if (str_starts_with($key, $alias.'::') && Database::isInternalAttribute($key)){ + continue; + } + // 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. @@ -4211,6 +4228,9 @@ public function updateDocument(string $collection, string $id, Document $documen if (\count($old->getAttribute($key)) !== \count($value)) { $shouldUpdate = true; + var_dump('$shouldUpdate 1'); + var_dump($shouldUpdate); + break; } @@ -4224,6 +4244,8 @@ public function updateDocument(string $collection, string $id, Document $documen ($relation instanceof Document && $relation->getId() !== $oldValue) ) { $shouldUpdate = true; + var_dump('$shouldUpdate 2'); + var_dump($shouldUpdate); break; } } @@ -4307,6 +4329,16 @@ public function updateDocument(string $collection, string $id, Document $documen $this->trigger(self::EVENT_DOCUMENT_UPDATE, $document); + /** + * Make this smarter + */ + $document->setAttribute('main::$id', $document->getId()); + $document->setAttribute('main::$sequence', $document->getSequence()); + $document->setAttribute('main::$permissions', $document->getPermissions()); + $document->setAttribute('main::$createdAt', $document->getCreatedAt()); + $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); + $document->setAttribute('main::$tenant', $document->getTenant()); + return $document; } diff --git a/src/Database/Document.php b/src/Database/Document.php index 65c034013..a8819cf25 100644 --- a/src/Database/Document.php +++ b/src/Database/Document.php @@ -80,17 +80,17 @@ public function getCollection(): string /** * @return array */ - public function getPermissions(): array + public function getPermissions(string $attribute = '$permissions'): array { - return \array_values(\array_unique($this->getAttribute('$permissions', []))); + return \array_values(\array_unique($this->getAttribute($attribute, []))); } /** * @return array */ - public function getRead(): array + public function getRead(string $attribute = '$permissions'): array { - return $this->getPermissionsByType(Database::PERMISSION_READ); + return $this->getPermissionsByType(Database::PERMISSION_READ, $attribute); } /** @@ -132,11 +132,11 @@ public function getWrite(): array /** * @return array */ - public function getPermissionsByType(string $type): array + public function getPermissionsByType(string $type, string $attribute = '$permissions'): array { $typePermissions = []; - foreach ($this->getPermissions() as $permission) { + foreach ($this->getPermissions($attribute) as $permission) { if (!\str_starts_with($permission, $type)) { continue; } diff --git a/tests/e2e/Adapter/Scopes/RelationshipTests.php b/tests/e2e/Adapter/Scopes/RelationshipTests.php index fa5eb888f..e39980bfa 100644 --- a/tests/e2e/Adapter/Scopes/RelationshipTests.php +++ b/tests/e2e/Adapter/Scopes/RelationshipTests.php @@ -751,10 +751,12 @@ public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void ])); var_dump($level1); + //$level1 = $database->getDocument('level1', $level1->getId()); $database->updateDocument('level1', $level1->getId(), new Document($level1->getArrayCopy())); $updatedLevel1 = $database->getDocument('level1', $level1->getId()); + $this->assertEquals($level1, $updatedLevel1); try { From ba87da6ea55ab6bc6ad53ffd6296c634f6d251ee Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 16 Jun 2025 11:56:57 +0300 Subject: [PATCH 04/10] Test return attributes --- src/Database/Database.php | 49 +++--- tests/e2e/Adapter/Scopes/DocumentTests.php | 146 ++++++++++++------ .../e2e/Adapter/Scopes/RelationshipTests.php | 67 ++++---- 3 files changed, 157 insertions(+), 105 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index d54811676..93eac970f 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3313,12 +3313,12 @@ public function getDocument(string $collection, string $id, array $queries = [], $queries, $forUpdate ); - if ($document->isEmpty()) { return $document; } $document->setAttribute('$collection', $collection->getId()); + $document->setAttribute('main::$collection', $collection->getId()); if ($collection->getId() !== self::METADATA) { if (!$validator->isValid([ @@ -3354,6 +3354,9 @@ public function getDocument(string $collection, string $id, array $queries = [], $this->trigger(self::EVENT_DOCUMENT_READ, $document); + $document->setAttribute('main::$createdAt', DateTime::formatTz($document->getAttribute('main::$createdAt'))); + $document->setAttribute('main::$updatedAt', DateTime::formatTz($document->getAttribute('main::$updatedAt'))); + return $document; } @@ -3692,6 +3695,7 @@ public function createDocument(string $collection, Document $document): Document $document->setAttribute('main::$createdAt', $document->getCreatedAt()); $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); $document->setAttribute('main::$tenant', $document->getTenant()); + $document->setAttribute('main::$collection', $document->getCollection()); return $document; } @@ -4015,7 +4019,7 @@ private function relateDocuments( if ($related->isEmpty()) { // If the related document doesn't exist, create it, inheriting permissions if none are set - if (!isset($relation['$permissions'])) { + if (!isset($relation['$permissions'])) { // todo: Should this be main::$permissions $relation->setAttribute('$permissions', $document->getPermissions()); } @@ -4228,9 +4232,6 @@ public function updateDocument(string $collection, string $id, Document $documen if (\count($old->getAttribute($key)) !== \count($value)) { $shouldUpdate = true; - var_dump('$shouldUpdate 1'); - var_dump($shouldUpdate); - break; } @@ -4244,8 +4245,6 @@ public function updateDocument(string $collection, string $id, Document $documen ($relation instanceof Document && $relation->getId() !== $oldValue) ) { $shouldUpdate = true; - var_dump('$shouldUpdate 2'); - var_dump($shouldUpdate); break; } } @@ -4329,15 +4328,13 @@ public function updateDocument(string $collection, string $id, Document $documen $this->trigger(self::EVENT_DOCUMENT_UPDATE, $document); - /** - * Make this smarter - */ $document->setAttribute('main::$id', $document->getId()); $document->setAttribute('main::$sequence', $document->getSequence()); $document->setAttribute('main::$permissions', $document->getPermissions()); $document->setAttribute('main::$createdAt', $document->getCreatedAt()); $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); $document->setAttribute('main::$tenant', $document->getTenant()); + $document->setAttribute('main::$collection', $document->getCollection()); return $document; } @@ -4616,7 +4613,7 @@ private function updateDocumentRelationships(Document $collection, Document $old $related = $this->skipRelationships( fn () => $this->getDocument($relatedCollection->getId(), $value, [Query::select(['$id'])]) ); - + var_dump($related); if ($related->isEmpty()) { // If no such document exists in related collection // For one-one we need to update the related key to null if no relation exists @@ -4639,6 +4636,13 @@ private function updateDocumentRelationships(Document $collection, Document $old $related->getId(), $related->setAttribute($twoWayKey, $document->getId()) )); + var_dump($relatedCollection->getId()); + var_dump($value); + var_dump(\gettype($value)); + var_dump($twoWay); + var_dump($twoWayKey); + var_dump($related); + var_dump($document->getId()); break; case 'object': if ($value instanceof Document) { @@ -4657,7 +4661,7 @@ private function updateDocumentRelationships(Document $collection, Document $old $this->relationshipWriteStack[] = $relatedCollection->getId(); if ($related->isEmpty()) { - if (!isset($value['$permissions'])) { + if (!isset($value['$permissions'])) {// todo check if should be main::$permissions $value->setAttribute('$permissions', $document->getAttribute('$permissions')); } $related = $this->createDocument( @@ -4746,7 +4750,7 @@ private function updateDocumentRelationships(Document $collection, Document $old ); if ($related->isEmpty()) { - if (!isset($relation['$permissions'])) { + if (!isset($relation['$permissions'])) { // todo check if should be main::$permissions $relation->setAttribute('$permissions', $document->getAttribute('$permissions')); } $this->createDocument( @@ -4786,7 +4790,7 @@ private function updateDocumentRelationships(Document $collection, Document $old ); if ($related->isEmpty()) { - if (!isset($value['$permissions'])) { + if (!isset($value['$permissions'])) { // todo check if should be main::$permissions $value->setAttribute('$permissions', $document->getAttribute('$permissions')); } $this->createDocument( @@ -4859,7 +4863,7 @@ private function updateDocumentRelationships(Document $collection, Document $old $related = $this->getDocument($relatedCollection->getId(), $relation->getId(), [Query::select(['$id'])]); if ($related->isEmpty()) { - if (!isset($value['$permissions'])) { + if (!isset($value['$permissions'])) {// todo check if should be main::$permissions $relation->setAttribute('$permissions', $document->getAttribute('$permissions')); } $related = $this->createDocument( @@ -6136,6 +6140,9 @@ public function find(string $collection, array $queries = [], string $forPermiss if (!$node->isEmpty()) { $node->setAttribute('$collection', $collection->getId()); + $node->setAttribute('main::$collection', DateTime::formatTz($node->getAttribute('main::$collection'))); + $node->setAttribute('main::$createdAt', DateTime::formatTz($node->getAttribute('main::$createdAt'))); + $node->setAttribute('main::$updatedAt', DateTime::formatTz($node->getAttribute('main::$updatedAt'))); } } @@ -6652,12 +6659,12 @@ private function validateSelections(Document $collection, array $queries): array $selections = \array_merge($selections, $relationshipSelections); - $selections[] = '$id'; - $selections[] = '$sequence'; - $selections[] = '$collection'; - $selections[] = '$createdAt'; - $selections[] = '$updatedAt'; - $selections[] = '$permissions'; +// $selections[] = '$id'; +// $selections[] = '$sequence'; +// $selections[] = '$collection'; +// $selections[] = '$createdAt'; +// $selections[] = '$updatedAt'; +// $selections[] = '$permissions'; return \array_values(\array_unique($selections)); } diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 562b9ebc6..2e1aa0d24 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -1129,26 +1129,38 @@ public function testGetDocumentSelect(Document $document): Document $this->assertArrayNotHasKey('boolean', $document->getAttributes()); $this->assertArrayNotHasKey('colors', $document->getAttributes()); $this->assertArrayNotHasKey('with-dash', $document->getAttributes()); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); - $this->assertArrayHasKey('$collection', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + //$this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayHasKey('main::$id', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); + $this->assertArrayHasKey('main::$collection', $document); $document = $database->getDocument('documents', $documentId, [ Query::select(['string', 'integer_signed', '$id']), ]); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); - $this->assertArrayHasKey('$collection', $document); $this->assertArrayHasKey('string', $document); $this->assertArrayHasKey('integer_signed', $document); + $this->assertArrayHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + //$this->assertArrayNotHasKey('$collection', $document); $this->assertArrayNotHasKey('float', $document); + $this->assertArrayHasKey('main::$id', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); + $this->assertArrayHasKey('main::$collection', $document); return $document; } @@ -2806,12 +2818,18 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + //$this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$id', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2825,11 +2843,17 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayNotHasKey('$sequence', $document); + //$this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$id', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2842,12 +2866,18 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); + $this->assertArrayNotHasKey('$id', $document); $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + //$this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$id', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2860,12 +2890,17 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2878,12 +2913,17 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + // $this->assertArrayNotHasKey('$collection', $document); $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2896,12 +2936,17 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + // $this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayNotHasKey('$createdAt', $document); $this->assertArrayHasKey('$updatedAt', $document); - $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayNotHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } $documents = $database->find('movies', [ @@ -2914,12 +2959,17 @@ public function testFindSelect(): void $this->assertArrayNotHasKey('director', $document); $this->assertArrayNotHasKey('price', $document); $this->assertArrayNotHasKey('active', $document); - $this->assertArrayHasKey('$id', $document); - $this->assertArrayHasKey('$sequence', $document); - $this->assertArrayHasKey('$collection', $document); - $this->assertArrayHasKey('$createdAt', $document); - $this->assertArrayHasKey('$updatedAt', $document); + $this->assertArrayNotHasKey('$id', $document); + $this->assertArrayNotHasKey('$sequence', $document); + //$this->assertArrayNotHasKey('$collection', $document); + $this->assertArrayNotHasKey('$createdAt', $document); + $this->assertArrayNotHasKey('$updatedAt', $document); $this->assertArrayHasKey('$permissions', $document); + $this->assertArrayHasKey('main::$sequence', $document); + $this->assertArrayHasKey('main::$collection', $document); + $this->assertArrayHasKey('main::$createdAt', $document); + $this->assertArrayHasKey('main::$updatedAt', $document); + $this->assertArrayHasKey('main::$permissions', $document); } } diff --git a/tests/e2e/Adapter/Scopes/RelationshipTests.php b/tests/e2e/Adapter/Scopes/RelationshipTests.php index e39980bfa..8d1bcd776 100644 --- a/tests/e2e/Adapter/Scopes/RelationshipTests.php +++ b/tests/e2e/Adapter/Scopes/RelationshipTests.php @@ -750,13 +750,8 @@ public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void ], ])); -var_dump($level1); - - //$level1 = $database->getDocument('level1', $level1->getId()); - $database->updateDocument('level1', $level1->getId(), new Document($level1->getArrayCopy())); $updatedLevel1 = $database->getDocument('level1', $level1->getId()); - $this->assertEquals($level1, $updatedLevel1); try { @@ -978,7 +973,7 @@ public function testSelectRelationshipAttributes(): void // Select some parent attributes, some child attributes $make = $database->findOne('make', [ - Query::select(['name', 'models.name']), + Query::select(['name', 'models.name', '*']), ]); if ($make->isEmpty()) { @@ -1009,11 +1004,11 @@ public function testSelectRelationshipAttributes(): void $this->assertArrayHasKey('name', $make); $this->assertArrayHasKey('$id', $make); - $this->assertArrayHasKey('$sequence', $make); - $this->assertArrayHasKey('$collection', $make); - $this->assertArrayHasKey('$createdAt', $make); - $this->assertArrayHasKey('$updatedAt', $make); - $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); + $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$sequence']), @@ -1024,12 +1019,12 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); - $this->assertArrayHasKey('$id', $make); $this->assertArrayHasKey('$sequence', $make); - $this->assertArrayHasKey('$collection', $make); - $this->assertArrayHasKey('$createdAt', $make); - $this->assertArrayHasKey('$updatedAt', $make); - $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); + $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$collection']), @@ -1040,12 +1035,12 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); - $this->assertArrayHasKey('$id', $make); - $this->assertArrayHasKey('$sequence', $make); $this->assertArrayHasKey('$collection', $make); - $this->assertArrayHasKey('$createdAt', $make); - $this->assertArrayHasKey('$updatedAt', $make); - $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); + $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$createdAt']), @@ -1056,12 +1051,12 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); - $this->assertArrayHasKey('$id', $make); - $this->assertArrayHasKey('$sequence', $make); - $this->assertArrayHasKey('$collection', $make); $this->assertArrayHasKey('$createdAt', $make); - $this->assertArrayHasKey('$updatedAt', $make); - $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); + $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$updatedAt']), @@ -1072,12 +1067,12 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); - $this->assertArrayHasKey('$id', $make); - $this->assertArrayHasKey('$sequence', $make); - $this->assertArrayHasKey('$collection', $make); - $this->assertArrayHasKey('$createdAt', $make); $this->assertArrayHasKey('$updatedAt', $make); - $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$permissions']), @@ -1088,12 +1083,12 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); - $this->assertArrayHasKey('$id', $make); - $this->assertArrayHasKey('$sequence', $make); - $this->assertArrayHasKey('$collection', $make); - $this->assertArrayHasKey('$createdAt', $make); - $this->assertArrayHasKey('$updatedAt', $make); $this->assertArrayHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); // Select all parent attributes, some child attributes $make = $database->findOne('make', [ From 8545413954922cf399334b3310aad7f39bb8b476 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 16 Jun 2025 17:18:31 +0300 Subject: [PATCH 05/10] Remove var_dump --- src/Database/Adapter/SQL.php | 6 ------ src/Database/Database.php | 10 ++-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 8f86baaa3..08e70e790 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -350,10 +350,6 @@ public function getDocument(string $collection, string $id, array $queries = [], $sql .= " {$forUpdate}"; } - if (!empty($selections)){ - echo $sql.PHP_EOL; - } - $stmt = $this->getPDO()->prepare($sql); $stmt->bindValue(':_uid', $id); @@ -1693,8 +1689,6 @@ public function getTenantQuery( */ protected function addHiddenAttribute(array $selects): string { - //return ''; - $alias = Query::DEFAULT_ALIAS; $strings = []; diff --git a/src/Database/Database.php b/src/Database/Database.php index 93eac970f..6ffc7c99b 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4613,7 +4613,7 @@ private function updateDocumentRelationships(Document $collection, Document $old $related = $this->skipRelationships( fn () => $this->getDocument($relatedCollection->getId(), $value, [Query::select(['$id'])]) ); - var_dump($related); + if ($related->isEmpty()) { // If no such document exists in related collection // For one-one we need to update the related key to null if no relation exists @@ -4636,13 +4636,7 @@ private function updateDocumentRelationships(Document $collection, Document $old $related->getId(), $related->setAttribute($twoWayKey, $document->getId()) )); - var_dump($relatedCollection->getId()); - var_dump($value); - var_dump(\gettype($value)); - var_dump($twoWay); - var_dump($twoWayKey); - var_dump($related); - var_dump($document->getId()); + break; case 'object': if ($value instanceof Document) { From 32c6884d5d526b01c154ad77e41026e7f6815e00 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 16 Jun 2025 17:21:26 +0300 Subject: [PATCH 06/10] Remove var_dump --- tests/e2e/Adapter/Scopes/RelationshipTests.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/e2e/Adapter/Scopes/RelationshipTests.php b/tests/e2e/Adapter/Scopes/RelationshipTests.php index 8d1bcd776..ac3db8a2a 100644 --- a/tests/e2e/Adapter/Scopes/RelationshipTests.php +++ b/tests/e2e/Adapter/Scopes/RelationshipTests.php @@ -749,7 +749,6 @@ public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void ], ], ])); - $database->updateDocument('level1', $level1->getId(), new Document($level1->getArrayCopy())); $updatedLevel1 = $database->getDocument('level1', $level1->getId()); $this->assertEquals($level1, $updatedLevel1); @@ -899,9 +898,6 @@ public function testNoInvalidKeysWithRelationships(): void ] ] ])); - - //$species = $database->getDocument('species', $species->getId()); - $database->updateDocument('species', $species->getId(), new Document([ '$id' => ID::custom('1'), '$collection' => 'species', From ed9c424d9c8208727166d25b430533afb6368a48 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 16 Jun 2025 17:29:05 +0300 Subject: [PATCH 07/10] tests internals RelationshipTests --- tests/e2e/Adapter/Scopes/DocumentTests.php | 2 +- .../e2e/Adapter/Scopes/RelationshipTests.php | 45 ++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 2e1aa0d24..51d1deb29 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -741,7 +741,7 @@ public function testUpsertDocumentsAttributeMismatch(): void $newDocument ->setAttribute('last', 'last') ]); -var_dump($docs); + $this->assertEquals(1, $docs); $this->assertEquals('first', $existingDocument->getAttribute('first')); diff --git a/tests/e2e/Adapter/Scopes/RelationshipTests.php b/tests/e2e/Adapter/Scopes/RelationshipTests.php index ac3db8a2a..cb0482055 100644 --- a/tests/e2e/Adapter/Scopes/RelationshipTests.php +++ b/tests/e2e/Adapter/Scopes/RelationshipTests.php @@ -988,6 +988,11 @@ public function testSelectRelationshipAttributes(): void $this->assertArrayHasKey('$collection', $make); $this->assertArrayHasKey('$createdAt', $make); $this->assertArrayHasKey('$updatedAt', $make); + $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); // Select internal attributes $make = $database->findOne('make', [ @@ -1000,11 +1005,16 @@ public function testSelectRelationshipAttributes(): void $this->assertArrayHasKey('name', $make); $this->assertArrayHasKey('$id', $make); + $this->assertArrayNotHasKey('$sequence', $make); + //$this->assertArrayNotHasKey('$collection', $make); + $this->assertArrayNotHasKey('$createdAt', $make); + $this->assertArrayNotHasKey('$updatedAt', $make); + $this->assertArrayNotHasKey('$permissions', $make); + $this->assertArrayHasKey('main::$id', $make); $this->assertArrayHasKey('main::$sequence', $make); $this->assertArrayHasKey('main::$collection', $make); $this->assertArrayHasKey('main::$createdAt', $make); $this->assertArrayHasKey('main::$updatedAt', $make); - $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$sequence']), @@ -1015,12 +1025,17 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); + $this->assertArrayNotHasKey('$id', $make); $this->assertArrayHasKey('$sequence', $make); + //$this->assertArrayHasKey('$collection', $make); + $this->assertArrayNotHasKey('$createdAt', $make); + $this->assertArrayNotHasKey('$updatedAt', $make); + $this->assertArrayNotHasKey('$permissions', $make); $this->assertArrayHasKey('main::$id', $make); + $this->assertArrayHasKey('main::$sequence', $make); $this->assertArrayHasKey('main::$collection', $make); $this->assertArrayHasKey('main::$createdAt', $make); $this->assertArrayHasKey('main::$updatedAt', $make); - $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$collection']), @@ -1031,12 +1046,17 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); + $this->assertArrayNotHasKey('$id', $make); + $this->assertArrayNotHasKey('$sequence', $make); $this->assertArrayHasKey('$collection', $make); + $this->assertArrayNotHasKey('$createdAt', $make); + $this->assertArrayNotHasKey('$updatedAt', $make); + $this->assertArrayNotHasKey('$permissions', $make); $this->assertArrayHasKey('main::$id', $make); $this->assertArrayHasKey('main::$sequence', $make); + $this->assertArrayHasKey('main::$collection', $make); $this->assertArrayHasKey('main::$createdAt', $make); $this->assertArrayHasKey('main::$updatedAt', $make); - $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$createdAt']), @@ -1047,12 +1067,17 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); + $this->assertArrayNotHasKey('$id', $make); + $this->assertArrayNotHasKey('$sequence', $make); + //$this->assertArrayHasKey('$collection', $make); $this->assertArrayHasKey('$createdAt', $make); + $this->assertArrayNotHasKey('$updatedAt', $make); + $this->assertArrayNotHasKey('$permissions', $make); $this->assertArrayHasKey('main::$id', $make); $this->assertArrayHasKey('main::$sequence', $make); $this->assertArrayHasKey('main::$collection', $make); + $this->assertArrayHasKey('main::$createdAt', $make); $this->assertArrayHasKey('main::$updatedAt', $make); - $this->assertArrayHasKey('main::$permissions', $make); $make = $database->findOne('make', [ Query::select(['name', '$updatedAt']), @@ -1063,12 +1088,17 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); + $this->assertArrayNotHasKey('$id', $make); + $this->assertArrayNotHasKey('$sequence', $make); + //$this->assertArrayHasKey('$collection', $make); + $this->assertArrayNotHasKey('$createdAt', $make); $this->assertArrayHasKey('$updatedAt', $make); + $this->assertArrayNotHasKey('$permissions', $make); $this->assertArrayHasKey('main::$id', $make); $this->assertArrayHasKey('main::$sequence', $make); $this->assertArrayHasKey('main::$collection', $make); $this->assertArrayHasKey('main::$createdAt', $make); - $this->assertArrayHasKey('main::$permissions', $make); + $this->assertArrayHasKey('main::$updatedAt', $make); $make = $database->findOne('make', [ Query::select(['name', '$permissions']), @@ -1079,6 +1109,11 @@ public function testSelectRelationshipAttributes(): void } $this->assertArrayHasKey('name', $make); + $this->assertArrayNotHasKey('$id', $make); + $this->assertArrayNotHasKey('$sequence', $make); + // $this->assertArrayHasKey('$collection', $make); + $this->assertArrayNotHasKey('$createdAt', $make); + $this->assertArrayNotHasKey('$updatedAt', $make); $this->assertArrayHasKey('$permissions', $make); $this->assertArrayHasKey('main::$id', $make); $this->assertArrayHasKey('main::$sequence', $make); From f71ee21b9fd5b4769d3964a4c3e67f4ce48721ac Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 16 Jun 2025 17:34:02 +0300 Subject: [PATCH 08/10] fix main::$collection --- src/Database/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 6ffc7c99b..e5d0d224e 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -6134,7 +6134,7 @@ public function find(string $collection, array $queries = [], string $forPermiss if (!$node->isEmpty()) { $node->setAttribute('$collection', $collection->getId()); - $node->setAttribute('main::$collection', DateTime::formatTz($node->getAttribute('main::$collection'))); + $node->setAttribute('main::$collection', $collection->getId()); $node->setAttribute('main::$createdAt', DateTime::formatTz($node->getAttribute('main::$createdAt'))); $node->setAttribute('main::$updatedAt', DateTime::formatTz($node->getAttribute('main::$updatedAt'))); } From 8b0bc4cfcdfa210e6b03c0c1d45184d1d6876d3a Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 17 Jun 2025 09:38:53 +0300 Subject: [PATCH 09/10] Fix test non share table --- src/Database/Database.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 69c49c6d5..e7125b00e 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3694,8 +3694,10 @@ public function createDocument(string $collection, Document $document): Document $document->setAttribute('main::$permissions', $document->getPermissions()); $document->setAttribute('main::$createdAt', $document->getCreatedAt()); $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); - $document->setAttribute('main::$tenant', $document->getTenant()); $document->setAttribute('main::$collection', $document->getCollection()); + if ($this->adapter->getSharedTables()) { + $document->setAttribute('main::$tenant', $document->getTenant()); + } return $document; } @@ -4333,8 +4335,10 @@ public function updateDocument(string $collection, string $id, Document $documen $document->setAttribute('main::$permissions', $document->getPermissions()); $document->setAttribute('main::$createdAt', $document->getCreatedAt()); $document->setAttribute('main::$updatedAt', $document->getUpdatedAt()); - $document->setAttribute('main::$tenant', $document->getTenant()); $document->setAttribute('main::$collection', $document->getCollection()); + if ($this->adapter->getSharedTables()) { + $document->setAttribute('main::$tenant', $document->getTenant()); + } return $document; } From b23b8a8a918819df634a5054a0ca5726e916dc90 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 17 Jun 2025 09:41:27 +0300 Subject: [PATCH 10/10] Remove hint --- src/Database/Database.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index e7125b00e..f4a826a4a 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4146,10 +4146,6 @@ public function updateDocument(string $collection, string $id, Document $documen $document = $this->withTransaction(function () use ($collection, $id, $document) { $time = DateTime::now(); - - /** - * @var $old Document - */ $old = Authorization::skip(fn () => $this->silent( fn () => $this->getDocument($collection->getId(), $id, forUpdate: true) ));