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
* alias-less column names to be used for a statement. The array needs to be in the following format:
* <pre><code>
* <code>
* array(
* 'table_name' => array(
* 'column1',
@ -62,7 +62,7 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
* 'alias2' => 'column3'
* )
* )
* <pre><code>
* </code>
*
* @var array
*/
@ -823,13 +823,17 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
return $statementAliasTableMap[$alias] === $table;
}
$prefixedAlias = $table . '.' . $alias;
if (isset($statementAliasTableMap[$prefixedAlias])) {
return true;
}
$statementColumnTableMap = $this->getStatementColumnTableMap();
if (isset($statementColumnTableMap[$alias])) {
return $statementColumnTableMap[$alias] === $table;
}
$prefixedAlias = $table . '.' . $alias;
return isset($statementAliasTableMap[$prefixedAlias]) || isset($statementColumnTableMap[$prefixedAlias]);
return isset($statementColumnTableMap[$prefixedAlias]);
}
/**

View File

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