DbRepository: Take virtual columns into consideration when applying aliases

This commit is contained in:
Johannes Meyer 2015-11-02 17:07:02 +01:00
parent 5db8d08729
commit 71c5fd0bf7

View File

@ -254,18 +254,25 @@ 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;
}
/** /**
* Return the given table with its alias being cleared * Return the given table with its alias being cleared
@ -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;
} }
return $this->prependTablePrefix($this->applyTableAlias($table)); $table = $newTable;
}
return $this->prependTablePrefix($this->applyTableAlias($table, $virtualTable));
} }
/** /**