Skip to content

Commit 7085327

Browse files
committed
RelationshipTests
1 parent 679c278 commit 7085327

File tree

5 files changed

+113
-86
lines changed

5 files changed

+113
-86
lines changed

src/Database/Database.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ public function analyzeCollection(string $collection): bool
15201520
public function deleteCollection(string $id): bool
15211521
{
15221522
$collection = $this->silent(fn () => $this->getDocument(self::METADATA, $id));
1523-
var_dump($collection->getAttribute('attributes'));
15241523

15251524
if ($collection->isEmpty()) {
15261525
throw new NotFoundException('Collection not found');
@@ -3373,13 +3372,12 @@ public function getDocument(string $collection, string $id, array $queries = [],
33733372
);
33743373

33753374
$selects = Query::getSelectQueries($queries);
3376-
[$selects, $permissionsAdded] = Query::addSelect($selects, Query::select('$permissions', system: true));
33773375

33783376
//$selects = $this->validateSelections($collection, $selects);
33793377

3380-
$result = $this->processRelationshipQueries($relationships, $selects);
3381-
$selects = $result['queries'];
3382-
$nestedSelections = $result['nestedSelections'];
3378+
[$selects, $nestedSelections] = $this->processRelationshipQueries($relationships, $selects);
3379+
3380+
[$selects, $permissionsAdded] = Query::addSelect($selects, Query::select('$permissions', system: true));
33833381

33843382
$validator = new Authorization(self::PERMISSION_READ);
33853383
$documentSecurity = $collection->getAttribute('documentSecurity', false);
@@ -3459,7 +3457,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
34593457
}
34603458
}
34613459

3462-
if($permissionsAdded){
3460+
if($permissionsAdded){ // Or remove all queries added by system
34633461
$document->removeAttribute('$permissions');
34643462
}
34653463

@@ -3478,7 +3476,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
34783476
private function populateDocumentRelationships(Document $collection, Document $document, array $selects = []): Document
34793477
{
34803478
if (empty($document->getId())){
3481-
throw new DatabaseException('$id is a required field');
3479+
throw new DatabaseException('$id is a required for populate Document Relationships');
34823480
}
34833481

34843482
$attributes = $collection->getAttribute('attributes', []);
@@ -3608,12 +3606,7 @@ private function populateDocumentRelationships(Document $collection, Document $d
36083606

36093607
$this->relationshipFetchDepth++;
36103608
$this->relationshipFetchStack[] = $relationship;
3611-
var_dump($relationships);
3612-
var_dump($side);
3613-
var_dump($document);
3614-
/**
3615-
* How to force $document->getId() , not to be empty?
3616-
*/
3609+
36173610
$relatedDocuments = $this->find($relatedCollection->getId(), [
36183611
Query::equal($twoWayKey, [$document->getId()]),
36193612
Query::limit(PHP_INT_MAX),
@@ -6340,9 +6333,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
63406333

63416334
//$selects = $this->validateSelections($collection, $selects);
63426335

6343-
$result = $this->processRelationshipQueries($relationships, $selects);
6344-
$selects = $result['queries'];
6345-
$nestedSelections = $result['nestedSelections'];
6336+
[$selects, $nestedSelections] = $this->processRelationshipQueries($relationships, $selects);
63466337

63476338
$results = $this->adapter->find(
63486339
$context,
@@ -6360,10 +6351,6 @@ public function find(string $collection, array $queries = [], string $forPermiss
63606351

63616352
foreach ($results as $index => $node) {
63626353
if ($this->resolveRelationships && !empty($relationships) && (empty($selects) || !empty($nestedSelections))) {
6363-
echo PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL;
6364-
var_dump('populateDocumentRelationships');
6365-
var_dump($collection->getId());
6366-
var_dump($nestedSelections);
63676354
$node = $this->silent(fn () => $this->populateDocumentRelationships($collection, $node, $nestedSelections));
63686355
}
63696356

@@ -7289,8 +7276,6 @@ private function processRelationshipQueries(
72897276
): array {
72907277
$nestedSelections = [];
72917278

7292-
$count = \count($queries);
7293-
72947279
foreach ($queries as $index => $query) {
72957280
if ($query->getMethod() !== Query::TYPE_SELECT) {
72967281
continue;
@@ -7349,14 +7334,14 @@ private function processRelationshipQueries(
73497334

73507335
$queries = array_values($queries);
73517336

7352-
// if ($count > 0 && empty($queries)) {
7353-
// $queries[] = Query::select('*');
7354-
// }
7337+
/**
7338+
* In order to populateDocumentRelationships we need $id
7339+
*/
7340+
if (\count($queries) > 0) {
7341+
[$queries, $idAdded] = Query::addSelect($queries, Query::select('$id', system: true));
7342+
}
73557343

7356-
return [
7357-
'queries' => $queries,
7358-
'nestedSelections' => $nestedSelections,
7359-
];
7344+
return [$queries, $nestedSelections];
73607345
}
73617346

73627347
/**

tests/e2e/Adapter/Base.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
abstract class Base extends TestCase
2121
{
22-
// use JoinsTests;
23-
// use CollectionTests;
24-
// use DocumentTests;
25-
// use AttributeTests;
26-
// use IndexTests;
27-
// use PermissionTests;
22+
// use JoinsTests;
23+
use CollectionTests;
24+
use DocumentTests;
25+
use AttributeTests;
26+
use IndexTests;
27+
use PermissionTests;
2828
use RelationshipTests;
2929
use SpatialTests;
3030
use GeneralTests;

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ public function testGetDocumentSelect(Document $document): Document
13181318
$this->assertArrayNotHasKey('boolean', $document->getAttributes());
13191319
$this->assertArrayNotHasKey('colors', $document->getAttributes());
13201320
$this->assertArrayNotHasKey('with-dash', $document->getAttributes());
1321-
$this->assertArrayNotHasKey('$id', $document);
1321+
$this->assertArrayHasKey('$id', $document);
13221322
$this->assertArrayNotHasKey('$sequence', $document);
13231323
$this->assertArrayNotHasKey('$createdAt', $document);
13241324
$this->assertArrayNotHasKey('$updatedAt', $document);
@@ -3461,7 +3461,7 @@ public function testFindSelect(): void
34613461
$this->assertArrayNotHasKey('director', $document);
34623462
$this->assertArrayNotHasKey('price', $document);
34633463
$this->assertArrayNotHasKey('active', $document);
3464-
$this->assertArrayNotHasKey('$id', $document);
3464+
$this->assertArrayHasKey('$id', $document);
34653465
$this->assertArrayNotHasKey('$sequence', $document);
34663466
$this->assertArrayHasKey('$collection', $document);
34673467
$this->assertArrayNotHasKey('$createdAt', $document);
@@ -3501,7 +3501,7 @@ public function testFindSelect(): void
35013501
$this->assertArrayNotHasKey('director', $document);
35023502
$this->assertArrayNotHasKey('price', $document);
35033503
$this->assertArrayNotHasKey('active', $document);
3504-
$this->assertArrayNotHasKey('$id', $document);
3504+
$this->assertArrayHasKey('$id', $document);
35053505
$this->assertArrayHasKey('$sequence', $document);
35063506
$this->assertArrayHasKey('$collection', $document);
35073507
$this->assertArrayNotHasKey('$createdAt', $document);
@@ -3521,7 +3521,7 @@ public function testFindSelect(): void
35213521
$this->assertArrayNotHasKey('director', $document);
35223522
$this->assertArrayNotHasKey('price', $document);
35233523
$this->assertArrayNotHasKey('active', $document);
3524-
$this->assertArrayNotHasKey('$id', $document);
3524+
$this->assertArrayHasKey('$id', $document);
35253525
$this->assertArrayNotHasKey('$sequence', $document);
35263526
$this->assertArrayHasKey('$collection', $document);
35273527
$this->assertArrayNotHasKey('$createdAt', $document);
@@ -3541,7 +3541,7 @@ public function testFindSelect(): void
35413541
$this->assertArrayNotHasKey('director', $document);
35423542
$this->assertArrayNotHasKey('price', $document);
35433543
$this->assertArrayNotHasKey('active', $document);
3544-
$this->assertArrayNotHasKey('$id', $document);
3544+
$this->assertArrayHasKey('$id', $document);
35453545
$this->assertArrayNotHasKey('$sequence', $document);
35463546
$this->assertArrayHasKey('$collection', $document);
35473547
$this->assertArrayHasKey('$createdAt', $document);
@@ -3561,7 +3561,7 @@ public function testFindSelect(): void
35613561
$this->assertArrayNotHasKey('director', $document);
35623562
$this->assertArrayNotHasKey('price', $document);
35633563
$this->assertArrayNotHasKey('active', $document);
3564-
$this->assertArrayNotHasKey('$id', $document);
3564+
$this->assertArrayHasKey('$id', $document);
35653565
$this->assertArrayNotHasKey('$sequence', $document);
35663566
$this->assertArrayHasKey('$collection', $document);
35673567
$this->assertArrayNotHasKey('$createdAt', $document);
@@ -3581,7 +3581,7 @@ public function testFindSelect(): void
35813581
$this->assertArrayNotHasKey('director', $document);
35823582
$this->assertArrayNotHasKey('price', $document);
35833583
$this->assertArrayNotHasKey('active', $document);
3584-
$this->assertArrayNotHasKey('$id', $document);
3584+
$this->assertArrayHasKey('$id', $document);
35853585
$this->assertArrayNotHasKey('$sequence', $document);
35863586
$this->assertArrayHasKey('$collection', $document);
35873587
$this->assertArrayNotHasKey('$createdAt', $document);

0 commit comments

Comments
 (0)