diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index d3584a437..88fd7d64f 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -1070,7 +1070,7 @@ abstract public function getKeywords(): array; * @param string $prefix * @return mixed */ - abstract protected function getAttributeProjection(array $selections, string $prefix = ''): mixed; + abstract protected function getAttributeProjection(array $selections, string $prefix): mixed; /** * Get all selected attributes from queries diff --git a/src/Database/Adapter/Pool.php b/src/Database/Adapter/Pool.php index b6bc54b08..302338aa9 100644 --- a/src/Database/Adapter/Pool.php +++ b/src/Database/Adapter/Pool.php @@ -455,7 +455,7 @@ public function getKeywords(): array return $this->delegate(__FUNCTION__, \func_get_args()); } - protected function getAttributeProjection(array $selections, string $prefix = ''): mixed + protected function getAttributeProjection(array $selections, string $prefix): mixed { return $this->delegate(__FUNCTION__, \func_get_args()); } diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 4c335bfba..31bc7e6a3 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -337,11 +337,13 @@ public function getDocument(string $collection, string $id, array $queries = [], $forUpdate = $forUpdate ? 'FOR UPDATE' : ''; + $alias = Query::DEFAULT_ALIAS; + $sql = " - SELECT {$this->getAttributeProjection($selections)} - FROM {$this->getSQLTable($name)} - WHERE _uid = :_uid - {$this->getTenantQuery($collection)} + SELECT {$this->getAttributeProjection($selections, $alias)} + FROM {$this->getSQLTable($name)} AS {$this->quote($alias)} + WHERE {$this->quote($alias)}.{$this->quote('_uid')} = :_uid + {$this->getTenantQuery($collection, $alias)} "; if ($this->getSupportForUpdateLock()) { @@ -1680,13 +1682,10 @@ public function getTenantQuery( * @return mixed * @throws Exception */ - protected function getAttributeProjection(array $selections, string $prefix = ''): mixed + protected function getAttributeProjection(array $selections, string $prefix): mixed { if (empty($selections) || \in_array('*', $selections)) { - if (!empty($prefix)) { - return "{$this->quote($prefix)}.*"; - } - return '*'; + return "{$this->quote($prefix)}.*"; } $internalKeys = [ @@ -1703,14 +1702,8 @@ protected function getAttributeProjection(array $selections, string $prefix = '' $selections[] = $this->getInternalKeyForAttribute($internalKey); } - if (!empty($prefix)) { - foreach ($selections as &$selection) { - $selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}"; - } - } else { - foreach ($selections as &$selection) { - $selection = "{$this->quote($this->filter($selection))}"; - } + foreach ($selections as &$selection) { + $selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}"; } return \implode(',', $selections);