mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
DbRepository: Take virtual columns into consideration when applying aliases
This commit is contained in:
parent
5db8d08729
commit
71c5fd0bf7
@ -254,17 +254,24 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
|
|||||||
* Return the given table with its alias being applied
|
* Return the given table with its alias being applied
|
||||||
*
|
*
|
||||||
* @param array|string $table
|
* @param array|string $table
|
||||||
|
* @param string $virtualTable
|
||||||
*
|
*
|
||||||
* @return array|string
|
* @return array|string
|
||||||
*/
|
*/
|
||||||
protected function applyTableAlias($table)
|
protected function applyTableAlias($table, $virtualTable = null)
|
||||||
{
|
{
|
||||||
$tableAliases = $this->getTableAliases();
|
$tableAliases = $this->getTableAliases();
|
||||||
if (is_array($table) || !isset($tableAliases[($nonPrefixedTable = $this->removeTablePrefix($table))])) {
|
if (! is_array($table)) {
|
||||||
return $table;
|
if ($virtualTable !== null && isset($tableAliases[$virtualTable])) {
|
||||||
|
return array($tableAliases[$virtualTable] => $table);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($tableAliases[($nonPrefixedTable = $this->removeTablePrefix($table))])) {
|
||||||
|
return array($tableAliases[$nonPrefixedTable] => $table);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($tableAliases[$nonPrefixedTable] => $table);
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -555,12 +562,18 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
|
|||||||
*/
|
*/
|
||||||
public function requireTable($table, RepositoryQuery $query = null)
|
public function requireTable($table, RepositoryQuery $query = null)
|
||||||
{
|
{
|
||||||
|
$virtualTable = null;
|
||||||
$statementColumns = $this->getStatementColumns();
|
$statementColumns = $this->getStatementColumns();
|
||||||
if (! isset($statementColumns[$table])) {
|
if (! isset($statementColumns[$table])) {
|
||||||
$table = parent::requireTable($table);
|
$newTable = parent::requireTable($table);
|
||||||
|
if ($newTable !== $table) {
|
||||||
|
$virtualTable = $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = $newTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->prependTablePrefix($this->applyTableAlias($table));
|
return $this->prependTablePrefix($this->applyTableAlias($table, $virtualTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user