Doctrine 查询语言中的左连接

发布于 2024-11-16 11:31:26 字数 457 浏览 0 评论 0原文

如果我没有在谷歌上做足够的研究,我想道歉,但说实话,我不知道到底要搜索什么。我的问题是教义。我使用 Symfony 框架,我想在 DQL 中编写以下原始查询:

SELECT c.id AS id,
c.name AS name,
c.active AS active,
count(c2.id) AS depth,
(c.rht - c.lft) as rng
FROM (categories c
LEFT JOIN categories c2 ON ( (c2.lft < c.lft) AND (c2.rht > c.rht) AND c2.active ) )
GROUP by c.id
ORDER by c.lft ASC

我可以像原始查询一样编写它,但我需要在 DQL 中使用它,因为我想将它用于 sfWidgetFormDoctrineChoice 小部件。非常感谢任何帮助。

提前致谢!

I want to apologies if I haven't done enough research in google but to be honest I don't know exactly what to search for. My problem is with Doctrine. I use Symfony framework and I want to write the following raw query in DQL:

SELECT c.id AS id,
c.name AS name,
c.active AS active,
count(c2.id) AS depth,
(c.rht - c.lft) as rng
FROM (categories c
LEFT JOIN categories c2 ON ( (c2.lft < c.lft) AND (c2.rht > c.rht) AND c2.active ) )
GROUP by c.id
ORDER by c.lft ASC

I can write it like a raw query, but I need it in DQL as I want to use it for a sfWidgetFormDoctrineChoice widget. Any help is highly appreciated.

Thanks in advance!

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

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

发布评论

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

评论(1

意犹 2024-11-23 11:31:26

一种可能的方法是:

$query = Doctrine_Query::create()
  ->select('c.name AS name,
            c.active AS active,
            count(c2.id) AS depth,
            (c.rht - c.lft) as rng')
  ->from('categories c')
  ->leftJoin('c.Categories c2 ON ( (c2.lft < c.lft) AND (c2.rht > c.rht) AND c2.active')
  ->groupBy('c.id')
  ->orderBy('c.lft ASC');

但我认为你的方式是错误的。你检查过教义树的行为吗? http://www.doctrine-project.org/documentation/manual/1_0/nl/hierarchical-data#nested-set:advanced-usage:fetching-a-tree-with-relations

A possible approuch would be:

$query = Doctrine_Query::create()
  ->select('c.name AS name,
            c.active AS active,
            count(c2.id) AS depth,
            (c.rht - c.lft) as rng')
  ->from('categories c')
  ->leftJoin('c.Categories c2 ON ( (c2.lft < c.lft) AND (c2.rht > c.rht) AND c2.active')
  ->groupBy('c.id')
  ->orderBy('c.lft ASC');

But I think your on the wrong way. Did you check out the tree behavior of doctrine? http://www.doctrine-project.org/documentation/manual/1_0/nl/hierarchical-data#nested-set:advanced-usage:fetching-a-tree-with-relations

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