From 9f988c4c854912675794dad654459e63f8087c4a Mon Sep 17 00:00:00 2001 From: Bas Date: Mon, 16 May 2022 11:37:53 +0200 Subject: [PATCH] Fixed passing of references and registered variables to the document function --- src/QueryBuilder.php | 1 - src/Traits/NormalizesMiscellaneousFunctions.php | 2 +- tests/Unit/AQL/MiscellaneousFunctionsTest.php | 10 ++++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 22acdea..e7d8ed6 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -164,7 +164,6 @@ public function registerVariable( if (is_string($variableName)) { $variableName = [$variableName => $variableName]; } - if (is_array($variableName)) { $this->variables = array_unique(array_merge($this->variables, $variableName)); } diff --git a/src/Traits/NormalizesMiscellaneousFunctions.php b/src/Traits/NormalizesMiscellaneousFunctions.php index c875750..d006752 100644 --- a/src/Traits/NormalizesMiscellaneousFunctions.php +++ b/src/Traits/NormalizesMiscellaneousFunctions.php @@ -44,7 +44,7 @@ protected function normalizeDocument(QueryBuilder $queryBuilder): void } $this->parameters['id'] = $queryBuilder->normalizeArgument( $this->parameters['id'], - ['Id', 'Key', 'Query', 'List', 'Bind'] + ['RegisteredVariable', 'Reference', 'Id', 'Key', 'Query', 'List', 'Bind'] ); } diff --git a/tests/Unit/AQL/MiscellaneousFunctionsTest.php b/tests/Unit/AQL/MiscellaneousFunctionsTest.php index 3b4134c..3e96631 100644 --- a/tests/Unit/AQL/MiscellaneousFunctionsTest.php +++ b/tests/Unit/AQL/MiscellaneousFunctionsTest.php @@ -65,6 +65,16 @@ public function testDocumentFunction() $qb = new QueryBuilder(); $qb->return($qb->document(['users/john', 'users/amy'])); self::assertEquals('RETURN DOCUMENT(["users/john","users/amy"])', $qb->get()->query); + + + $qb = new QueryBuilder(); + $qb->let('variable', 'collection/a') + ->return($qb->document("pages", 'variable')); + + self::assertEquals( + 'LET variable = @' . $qb->getQueryId() . '_1 RETURN DOCUMENT(pages, variable)', + $qb->get()->query + ); } public function testCurrentDatabase()