Symfony2,dql不能与REPEAT函数一起使用

时间:2012-10-07 12:45:37

标签: symfony doctrine-orm dql

public function mpttLocationList() {
        $q = $this->_em->createQuery("
        SELECT CONCAT(REPEAT('.', COUNT(parent.region_name) - 1), node.region_name) AS name
        FROM ViveListingBundle:region_redefine AS node,
                ViveListingBundle:region_redefine AS parent
        WHERE node.lft BETWEEN parent.lft AND parent.rgt
        GROUP BY node.region_name
        ORDER BY node.lft");
        return $q->getResult();
    } 

上面的代码给出了错误:

[Syntax Error] line 0, col 23: Error: Expected known function, got 'REPEAT'.

2 个答案:

答案 0 :(得分:0)

REPEAT不是有效的DQL函数。记住DQL不是SQL,它看起来很相似,但它有重要的区别,不支持所有的SQL结构。查看DQL文档以查看支持的内容:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html

答案 1 :(得分:0)

要教授关于REPEAT()的学说,您需要define a custom DQL functionregister it with Symfony