Skip to content

Commit 1393df5

Browse files
committed
Report reverse one-way relationship errors before array cardinality errors
1 parent 6c62d5b commit 1393df5

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/Database/Database.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,6 +5998,10 @@ private function createDocumentRelationships(Document $collection, Document $doc
59985998
try {
59995999
switch (\gettype($value)) {
60006000
case 'array':
6001+
if ($relationType === Database::RELATION_ONE_TO_ONE && !$twoWay && $side === Database::RELATION_SIDE_CHILD) {
6002+
throw new RelationshipException('Invalid relationship value. Cannot set a value from the child side of a oneToOne relationship when twoWay is false.');
6003+
}
6004+
60016005
if (
60026006
($relationType === Database::RELATION_MANY_TO_ONE && $side === Database::RELATION_SIDE_PARENT) ||
60036007
($relationType === Database::RELATION_ONE_TO_MANY && $side === Database::RELATION_SIDE_CHILD) ||

‎tests/e2e/Adapter/Scopes/Relationships/OneToOneTests.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public function testCreateOneWayReverseRelationshipError(): void
2828

2929
$parents = ID::unique();
3030
$children = ID::unique();
31-
$database->createCollection($parents);
32-
$database->createCollection($children);
31+
$permissions = [Permission::read(Role::any()), Permission::create(Role::any()), Permission::update(Role::any())];
32+
$database->createCollection($parents, [], [], $permissions);
33+
$database->createCollection($children, [], [], $permissions);
3334
$database->createAttribute($parents, 'name', Database::VAR_STRING, 255, false);
3435
$database->createRelationship($parents, $children, Database::RELATION_ONE_TO_ONE, false, 'child', 'parent', Database::RELATION_MUTATE_SET_NULL);
3536
$database->createDocument($parents, new Document(['$id' => 'parent']));

0 commit comments

Comments
 (0)