Doctrine 1.2,在多对多表上运行查询

发布于 2024-11-30 04:49:07 字数 398 浏览 5 评论 0原文

我想在 Doctrine 1.2 下自动生成的表上进行查询。在这种特殊情况下,我有以下查询:

SELECT F.id FROM ficha as F JOIN ficha_has_tema FT ON FT.ficha_id = F.id WHERE FT.tema_id = ? GROUP BY F.id HAVING COUNT(F.id) > 1

但我收到错误:

未捕获的异常“Doctrine_Exception”,消息为“找不到” ficha_has_tema' 类位于...

那么,有没有一种方法可以使用学说进行此查询而不创建类 ficha_has_tema?我需要进行计数。

谢谢!

I want to make a query on an automatic generated table under Doctrine 1.2. In this particular case I have the following query:

SELECT F.id FROM ficha as F JOIN ficha_has_tema FT ON FT.ficha_id = F.id WHERE FT.tema_id = ? GROUP BY F.id HAVING COUNT(F.id) > 1

But I get the error:

Uncaught exception 'Doctrine_Exception' with message 'Couldn't find
class ficha_has_tema' in...

So, is there a way to make this query using doctrine without creating the class ficha_has_tema? I need to do the COUNT.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-12-07 04:49:07

我假设您正在此处执行 DQL 查询。不可能使用在 SQL 查询中没有关联实体的表。

运行旧式 SQL

$q = Doctrine_Manager::getInstance()->getCurrentConnection();
$result = $q->execute("SELECT F.id FROM ficha as F JOIN ficha_has_tema FT ON FT.ficha_id = F.id WHERE FT.tema_id = ? GROUP BY F.id HAVING COUNT(F.id) > 1");

但是,您可以按照“将原始 SQL 与 Doctrine 结合使用”

或者 Doctrine Native SQL Support 之类的东西(从未亲自尝试过,可能需要一些修改)

$q = new Doctrine_RawSql();
$q->select("{F.id}")
  ->from("
        From ficha as F 
        JOIN ficha_has_tema FT ON FT.ficha_id = F.id 
        WHERE FT.tema_id = ? 
        GROUP BY F.id 
        HAVING COUNT(F.id) > 1"
    );

$result = $q->execute(array($tema_id));

I assume you are executing DQL query here. It's impossible to use tables that have no associated entities wihthin the SQL queries.

However, you may run good-old SQL with

$q = Doctrine_Manager::getInstance()->getCurrentConnection();
$result = $q->execute("SELECT F.id FROM ficha as F JOIN ficha_has_tema FT ON FT.ficha_id = F.id WHERE FT.tema_id = ? GROUP BY F.id HAVING COUNT(F.id) > 1");

as suggested in "Using Raw SQL with Doctrine"

Or Doctrine Native SQL Support with something like (never tried that personally, might require some modification)

$q = new Doctrine_RawSql();
$q->select("{F.id}")
  ->from("
        From ficha as F 
        JOIN ficha_has_tema FT ON FT.ficha_id = F.id 
        WHERE FT.tema_id = ? 
        GROUP BY F.id 
        HAVING COUNT(F.id) > 1"
    );

$result = $q->execute(array($tema_id));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文