【发布时间】:2012-06-04 02:57:54
【问题描述】:
我正在玩DoctrineExtensions,但无法管理它。注册 DoctrineExtensions 后,我在 Zend Framework 中有以下 DQL 行:
$qb->having(new IfElse("A.type = 0", new FindInSet(1, new GroupConcat('B.id', ',')) >0 , '1') );
但是得到这个错误消息:
异常信息:
消息:'DoctrineExtensions\Query\Mysql\IfElse' 类型的表达式 在这种情况下不允许。*
您能帮我指出我的命令或任何有关如何使用 DoctrineExtensions 的文档中有哪些不正确之处吗?
更新:
我找到了一种实现自定义功能的方法: 我通过将这一行添加到 boostrap 来尝试一下:
$config->addCustomStringFunction('IF', 'DoctrineExtensions\Query\Mysql\IfElse');
并在 DQL 中将其用作:
$qb->having("IF( A.type = 0, S.status = 0, S.status = 1 )");
但是得到这个错误:
消息:[语法错误] line 0, col 152: Error: Expected Doctrine\ORM\Query\Lexer::T_COMMA, got '='
也许我的语法有误?
【问题讨论】:
-
我回来晚了,在这里给遇到同样问题的人留下评论。这比原来的问题要复杂一些,但我所拥有的是: $qb->having("IF (" . $qb->expr()->neq('S.userId', $arrCondition['current_user']) . ", IF ( FIND_IN_SET(" . $arrCondition['current_user'] . ", IF ( i.type > 1 , '',IF (i.type = 0, GROUP_CONCAT(i.receiver), GROUP_CONCAT(i.createdBy ) )) ) >= 0, i.status, 0 ), 1 ) = 1" );
标签: if-statement doctrine doctrine-orm