Skip to content

Commit 576ca46

Browse files
committed
fix
1 parent cff2b6e commit 576ca46

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/Database/Database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,8 @@ public function createRelationship(
35893589
}
35903590

35913591
if (
3592-
$attribute->getAttribute('type') === self::VAR_RELATIONSHIP
3592+
$twoWay
3593+
&& $attribute->getAttribute('type') === self::VAR_RELATIONSHIP
35933594
&& \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey)
35943595
&& $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId()
35953596
) {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,25 +1024,22 @@ public function testIdenticalTwoWayKeyRelationship(): void
10241024
id: 'child1'
10251025
);
10261026

1027-
try {
1028-
$database->createRelationship(
1029-
collection: 'parent',
1030-
relatedCollection: 'child',
1031-
type: Database::RELATION_ONE_TO_MANY,
1032-
id: 'children',
1033-
);
1034-
$this->fail('Failed to throw Exception');
1035-
} catch (Exception $e) {
1036-
$this->assertEquals('Related attribute already exists', $e->getMessage());
1037-
}
1038-
1039-
$database->createRelationship(
1027+
$result = $database->createRelationship(
10401028
collection: 'parent',
10411029
relatedCollection: 'child',
10421030
type: Database::RELATION_ONE_TO_MANY,
10431031
id: 'children',
1032+
);
1033+
$this->assertTrue($result);
1034+
1035+
$result = $database->createRelationship(
1036+
collection: 'parent',
1037+
relatedCollection: 'child',
1038+
type: Database::RELATION_ONE_TO_MANY,
1039+
id: 'childrenById',
10441040
twoWayKey: 'parent_id'
10451041
);
1042+
$this->assertTrue($result);
10461043

10471044
$collection = $database->getCollection('parent');
10481045
$attributes = $collection->getAttribute('attributes', []);
@@ -1052,6 +1049,10 @@ public function testIdenticalTwoWayKeyRelationship(): void
10521049
}
10531050

10541051
if ($attribute['key'] === 'children') {
1052+
$this->assertEquals('parent', $attribute['options']['twoWayKey']);
1053+
}
1054+
1055+
if ($attribute['key'] === 'childrenById') {
10551056
$this->assertEquals('parent_id', $attribute['options']['twoWayKey']);
10561057
}
10571058
}

0 commit comments

Comments
 (0)