Doctrine 条令:未知的表别名。这个DQL正确吗?

Doctrine 条令:未知的表别名。这个DQL正确吗?,doctrine,dql,Doctrine,Dql,我正在尝试执行查询,但出现错误: 未知表别名 表的设置如下所示: Template_Spot hasOne Template Template hasMany Template_Spot Template hasMany Location Location hasOne Template 我正在尝试执行以下DQL: $locationid = 1; $spots = Doctrine_Query::create() ->select('cts.*

我正在尝试执行查询,但出现错误:

未知表别名

表的设置如下所示:

Template_Spot hasOne  Template
Template      hasMany Template_Spot
Template      hasMany Location
Location      hasOne  Template
我正在尝试执行以下DQL:

$locationid = 1;
$spots = Doctrine_Query::create()
    ->select('cts.*, ct.*, uc.*')
    ->from('Template_Spot cts')
    ->innerJoin('Template ct')
    ->innerJoin('Location uc')
    ->where('uc.locationid = ?', $locationid)->execute();

有人发现问题吗?

如果您选择了所有字段,则根本不需要
->select()

难道不是:

$spots = Doctrine_Query::create()
    ->from('Template_Spot cts')
    ->leftJoin('Template ct')
    ->leftJoin('Location uc')
    ->where('uc.id = ?', $locationid)
    ->execute();

尝试找出哪些表别名未被识别。我认为这是在尝试将Template_Spot与Location结合起来,在这种情况下,您可能需要执行以下操作:

[pseudo code]
FROM Template_Spot cts, cts.Template ct, ct.Location uc

有时,仅在模式中定义别名和外来别名也可能有所帮助,但原则很容易混淆。对于这样的多个连接,Doctrine有时可能会生成比需要更多的SQL查询,您可能希望完全绕过DQL。

应该是cts.Template ct和cts.Location uc,因为Template_Spot是一个带有额外列的refclass。是否应该以不同的方式加载这些文件?