Doctrine:未知的表别名。这个DQL是否正确?

时间:2010-04-16 00:39:39

标签: 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.*, ct.*, uc.*')
    ->from('Template_Spot cts')
    ->innerJoin('Template ct')
    ->innerJoin('Location uc')
    ->where('uc.locationid = ?', $locationid)->execute();

是否有人发现问题?

2 个答案:

答案 0 :(得分:1)

尝试找出哪些表别名未被识别。我认为它正在尝试将Template_Spot与Location连接,在这种情况下您可能需要这样做:

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

有时只是在模式中定义Alias和foreignAlias名称也可能有所帮助,Doctrine很容易混淆。有了这样的多个连接,Doctrine有时可能会生成超过必要的SQL查询,您可能希望完全绕过DQL。

答案 1 :(得分:0)

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

不应该是:

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