Skip to content

Commit fd05e50

Browse files
committed
Remove internal attributes not queried
1 parent 1346015 commit fd05e50

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Database/Database.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,13 +3097,14 @@ public function getDocument(string $collection, string $id, array $queries = [],
30973097
// Remove internal attributes if not queried for select query
30983098
// $id, $permissions and $collection are the default selected attributes for (MariaDB, MySQL, SQLite, Postgres)
30993099
// All internal attributes are default selected attributes for (MongoDB)
3100-
foreach ($selects as $query) {
3101-
if ($query->getMethod() === Query::TYPE_SELECT) {
3102-
$values = $query->getValues();
3103-
foreach ($this->getInternalAttributes() as $internalAttribute) {
3104-
if (!\in_array($internalAttribute['$id'], $values)) {
3105-
$document->removeAttribute($internalAttribute['$id']);
3106-
}
3100+
if (!empty($selects)) {
3101+
$selectedAttributes = array_map(fn($q) => $q->getAttribute(), $selects);
3102+
3103+
foreach ($this->getInternalAttributes() as $internalAttribute) {
3104+
$attributeId = $internalAttribute['$id'];
3105+
3106+
if (!in_array($attributeId, $selectedAttributes, true)) {
3107+
$document->removeAttribute($attributeId);
31073108
}
31083109
}
31093110
}

0 commit comments

Comments
 (0)