我这样加入我的桌子时出错:
$queryBuilder = $conn->createQueryBuilder();
$queryBuilder->select('*')
->from('table1','t1')
->innerJoin('t1','table2','t2', 't1.id = t2.id' )
->innerJoin('t2','table3','t3', 't2.id = t3.id' )
;
$queryBuilder->getSQL();
致命错误:未捕获的异常' Doctrine \ DBAL \ Query \ QueryException'与消息'给定的别名' t2'不是任何FROM子句表的一部分。当前注册的FROM子句别名为:t1。 Join子句与from子句绑定,以支持混合多个from和join子句。
在getSQLForSelect中,似乎构建器仅检查与from链接的连接,而不是与其他连接链接的连接:
if (isset($this->sqlParts['join'][$from['alias']])) {
foreach ($this->sqlParts['join'][$from['alias']] as $join) {
$fromClause .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias']
. ' ON ' . ((string) $join['joinCondition']);
}
}
改变这似乎有效,但它很脏(并带来其他人的pbs)
if (isset($this->sqlParts['join'])) {
foreach ($this->sqlParts['join'] as $joins) {
foreach ($joins as $join) {
$fromClause .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias']
. ' ON ' . ((string) $join['joinCondition']);
}
}
}