Repository: Check prefixed aliases earlier when inspecting $aliasTableMap

Avoids false-positives in case an exact match using $columnTableMap is
possible, though $aliasTableMap holds a prefixed entry.
This commit is contained in:
Johannes Meyer 2017-06-06 09:12:43 +02:00
parent fdb31e8d1c
commit 7482a34b45
2 changed files with 20 additions and 12 deletions

View File

@ -54,7 +54,7 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
* *
* This may be initialized by repositories which are going to make use of table aliases. It allows to provide * This may be initialized by repositories which are going to make use of table aliases. It allows to provide
* alias-less column names to be used for a statement. The array needs to be in the following format: * alias-less column names to be used for a statement. The array needs to be in the following format:
* <pre><code> * <code>
* array( * array(
* 'table_name' => array( * 'table_name' => array(
* 'column1', * 'column1',
@ -62,7 +62,7 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
* 'alias2' => 'column3' * 'alias2' => 'column3'
* ) * )
* ) * )
* <pre><code> * </code>
* *
* @var array * @var array
*/ */
@ -823,13 +823,17 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
return $statementAliasTableMap[$alias] === $table; return $statementAliasTableMap[$alias] === $table;
} }
$prefixedAlias = $table . '.' . $alias;
if (isset($statementAliasTableMap[$prefixedAlias])) {
return true;
}
$statementColumnTableMap = $this->getStatementColumnTableMap(); $statementColumnTableMap = $this->getStatementColumnTableMap();
if (isset($statementColumnTableMap[$alias])) { if (isset($statementColumnTableMap[$alias])) {
return $statementColumnTableMap[$alias] === $table; return $statementColumnTableMap[$alias] === $table;
} }
$prefixedAlias = $table . '.' . $alias; return isset($statementColumnTableMap[$prefixedAlias]);
return isset($statementAliasTableMap[$prefixedAlias]) || isset($statementColumnTableMap[$prefixedAlias]);
} }
/** /**

View File

@ -67,7 +67,7 @@ abstract class Repository implements Selectable
* The query columns being provided * The query columns being provided
* *
* This must be initialized by concrete repository implementations, in the following format * This must be initialized by concrete repository implementations, in the following format
* <pre><code> * <code>
* array( * array(
* 'baseTable' => array( * 'baseTable' => array(
* 'column1', * 'column1',
@ -75,7 +75,7 @@ abstract class Repository implements Selectable
* 'alias2' => 'column3' * 'alias2' => 'column3'
* ) * )
* ) * )
* </code></pre> * </code>
* *
* @var array * @var array
*/ */
@ -101,12 +101,12 @@ abstract class Repository implements Selectable
* The filter columns being provided * The filter columns being provided
* *
* This may be intialized by concrete repository implementations, in the following format * This may be intialized by concrete repository implementations, in the following format
* <pre><code> * <code>
* array( * array(
* 'alias_or_column_name', * 'alias_or_column_name',
* 'label_to_show_in_the_filter_editor' => 'alias_or_column_name' * 'label_to_show_in_the_filter_editor' => 'alias_or_column_name'
* ) * )
* </code></pre> * </code>
* *
* @var array * @var array
*/ */
@ -137,7 +137,7 @@ abstract class Repository implements Selectable
* The sort rules to be applied on a query * The sort rules to be applied on a query
* *
* This may be initialized by concrete repository implementations, in the following format * This may be initialized by concrete repository implementations, in the following format
* <pre><code> * <code>
* array( * array(
* 'alias_or_column_name' => array( * 'alias_or_column_name' => array(
* 'order' => 'asc' * 'order' => 'asc'
@ -154,7 +154,7 @@ abstract class Repository implements Selectable
* // Ascendant sort by default * // Ascendant sort by default
* ) * )
* ) * )
* </code></pre> * </code>
* Note that it's mandatory to supply the alias name in case there is one. * Note that it's mandatory to supply the alias name in case there is one.
* *
* @var array * @var array
@ -1094,13 +1094,17 @@ abstract class Repository implements Selectable
return $aliasTableMap[$alias] === $table; return $aliasTableMap[$alias] === $table;
} }
$prefixedAlias = $table . '.' . $alias;
if (isset($aliasTableMap[$prefixedAlias])) {
return true;
}
$columnTableMap = $this->getColumnTableMap(); $columnTableMap = $this->getColumnTableMap();
if (isset($columnTableMap[$alias])) { if (isset($columnTableMap[$alias])) {
return $columnTableMap[$alias] === $table; return $columnTableMap[$alias] === $table;
} }
$prefixedAlias = $table . '.' . $alias; return isset($columnTableMap[$prefixedAlias]);
return isset($aliasTableMap[$prefixedAlias]) || isset($columnTableMap[$prefixedAlias]);
} }
/** /**