0

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

未知的表别名

表设置如下:

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();

有人发现问题吗?

4

2 回答 2

1

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

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

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

于 2010-04-16T13:41:04.703 回答
0

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

不应该是:

$spots = Doctrine_Query::create()
    ->from('Template_Spot cts')
    ->leftJoin('Template ct')
    ->leftJoin('Location uc')
    ->where('uc.id = ?', $locationid)
    ->execute();
于 2010-04-16T06:46:18.167 回答