if ( is_array( $table ) ) {
// A parenthesized group
- $joinedTable = '('
- . $this->tableNamesWithIndexClauseOrJOIN( $table, $use_index, $ignore_index, $join_conds )
- . ')';
+ if ( count( $table ) > 1 ) {
+ $joinedTable = '('
+ . $this->tableNamesWithIndexClauseOrJOIN( $table, $use_index, $ignore_index, $join_conds )
+ . ')';
+ } else {
+ // Degenerate case
+ $innerTable = reset( $table );
+ $innerAlias = key( $table );
+ $joinedTable = $this->tableNameWithAlias(
+ $innerTable,
+ is_string( $innerAlias ) ? $innerAlias : $innerTable
+ );
+ }
} else {
$joinedTable = $this->tableNameWithAlias( $table, $alias );
}
],
'table1 LEFT JOIN (table2 JOIN table3 ON ((t2_id = t3_id))) ON ((t1_id = t2_id))'
],
+ 'join with degenerate parenthesized group' => [
+ [ 'table1', 'n' => [ 't2' => 'table2' ] ],
+ [
+ 'n' => [ 'LEFT JOIN', 't1_id = t2_id' ],
+ ],
+ 'table1 LEFT JOIN table2 t2 ON ((t1_id = t2_id))'
+ ],
];
}