QueryRestrictionBuilder restrictions not working when using table multiple times in one query
For several reasons it is sometimes necessary to join a table in a single query which is used before. This can be in ->from() or another ->join().
When using a statement like
$statement = $queryBuilder ->select('original.*') ->from('pages', 'original') ->join( 'original', 'pages', 'similar', $queryBuilder->expr()->eq( 'similar.uid', <PUT_SOME_UID_HERE> ) ) ...
or joining the same table multiple times will only add the restrictions for the last mentioned table.
This is due to the fact the method "getQueriedTables()" in the "QueryBuilder" does not take multiple use of a single table into account. The array returned from this method will look like
[ 'pages' => 'similar' ]
while it should be multidimensional like
[ 'pages' => [ 'original' 'similar' ] ]
While setting this array it will overwrite the alias "original" with the second one "similar".
The RestrictionBuilder is using this array to iterate over all tables setting their restrictions, which fails for "original". The RestrictionBuilder should also take into account there can be multiple use of one table, using the multidimensional array.
Updated by Tymoteusz Motylewski almost 7 years ago
This issue is e.g. present in LocalizationRepository::fetchOriginLanguage
The query there is inner joining tt_content with self (alias tt_content_orig) which results in delete where clause being added only for tt_content_orig and not for tt_content.