diff --git a/src/Database/Validator/Structure.php b/src/Database/Validator/Structure.php index 3d7d2ade7..db57ce8d8 100644 --- a/src/Database/Validator/Structure.php +++ b/src/Database/Validator/Structure.php @@ -254,6 +254,10 @@ public function isValid($document): bool continue; } + if($type === Database::VAR_RELATIONSHIP) { + continue; + } + switch ($type) { case Database::VAR_STRING: $size = $attribute['size'] ?? 0; @@ -276,8 +280,6 @@ public function isValid($document): bool $validator = new DatetimeValidator(); break; - case Database::VAR_RELATIONSHIP: - return true; default: $this->message = 'Unknown attribute type "'.$type.'"'; return false; diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 7d47a0f40..9fbd9e54b 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -3898,6 +3898,36 @@ public function testNoChangeUpdateDocumentWithoutPermission(Document $document): return $document; } + public function testStructureValidationAfterRelationsAttribute(): void + { + if (!static::getDatabase()->getAdapter()->getSupportForRelationships()) { + $this->expectNotToPerformAssertions(); + return; + } + + static::getDatabase()->createCollection("structure_1", [], [], [Permission::create(Role::any())]); + static::getDatabase()->createCollection("structure_2", [], [], [Permission::create(Role::any())]); + + static::getDatabase()->createRelationship( + collection: "structure_1", + relatedCollection: "structure_2", + type: Database::RELATION_ONE_TO_ONE, + ); + + try { + static::getDatabase()->createDocument('structure_1', new Document([ + '$permissions' => [ + Permission::read(Role::any()), + ], + 'structure_2' => '100', + 'name' => 'Frozen', // Unknown attribute 'name' after relation attribute + ])); + $this->fail('Failed to throw exception'); + } catch(Exception $e) { + $this->assertInstanceOf(StructureException::class, $e); + } + } + public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void { if (!static::getDatabase()->getAdapter()->getSupportForRelationships()) {