PHP-在学说查询语言中的左联接
作者:互联网
如果我没有在Google上进行足够的研究,我想道歉,但老实说,我不知道要搜索什么.我的问题是教义.我使用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
我可以像原始查询一样编写它,但是我想在sfWidgetFormDoctrineChoice小部件中使用它,因此在DQL中需要它.非常感谢您的帮助.
提前致谢!
解决方法:
可能的副官是:
$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
标签:doctrine,symfony1,mysql,php 来源: https://codeday.me/bug/20191208/2090072.html