From 6cddb38290b640cda35204fd23b91818ba7c97bf Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 24 Mar 2023 20:30:41 +1300 Subject: [PATCH] Fix for count --- app/controllers/api/databases.php | 7 +++++++ .../Utopia/Database/Validator/Query/Filter.php | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c44d5f55ce..ec7f5ec58b 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2751,6 +2751,13 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $filterQueries = Query::groupByType($queries)['filters']; + // TODO: Remove this when we have a better way to handle nested attribute queries + foreach ($filterQueries as $key => $query) { + if (\str_contains($query->getAttribute(), '.')) { + unset($filterQueries[$key]); + } + } + if ($documentSecurity && !$valid) { $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries, APP_LIMIT_COUNT); diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Filter.php b/src/Appwrite/Utopia/Database/Validator/Query/Filter.php index 0be5ac7aad..5b045672e0 100644 --- a/src/Appwrite/Utopia/Database/Validator/Query/Filter.php +++ b/src/Appwrite/Utopia/Database/Validator/Query/Filter.php @@ -34,6 +34,12 @@ class Filter extends Base protected function isValidAttribute($attribute): bool { + if (\str_contains($attribute, '.')) { + // For relationships, just validate the top level. + // Utopia will validate each nested level during the recursive calls. + $attribute = \explode('.', $attribute)[0]; + } + // Search for attribute in schema if (!isset($this->schema[$attribute])) { $this->message = 'Attribute not found in schema: ' . $attribute; @@ -49,6 +55,12 @@ class Filter extends Base return false; } + if (\str_contains($attribute, '.')) { + // For relationships, just validate the top level. + // Utopia will validate each nested level during the recursive calls. + $attribute = \explode('.', $attribute)[0]; + } + $attributeSchema = $this->schema[$attribute]; if (count($values) > $this->maxValuesCount) {