问题描述
我一直在浏览文档/谷歌,但没有找到任何解决方案.
i've been looking through the docs/google and didn't find any solution.
有没有什么方法可以在没有本地mysql的情况下使用doctrine2(DQL)来执行或模仿GROUP_CONCAT?
is there any way to execute or imitate GROUP_CONCAT using doctrine2 (DQL) without native mysql?
例如:
SELECT u.id, u.name, [GROUP_CONCAT(...)] AS user_messages
FROM modelsUsers u
LEFT JOIN modelsMessages m
GROUP BY u.id
得到
GROUP_CONCAT(m.id,'|',m.title SEPARATOR ':')
现在我正在使用 createNativeQuery() 来运行它,但我正在寻找一个 docter2 解决方案.
right now i'm using the createNativeQuery() to run it, but i'm looking for a doctrine2 solution.
提前致谢
推荐答案
是的,这可以通过 Beberlei(Doctrine2 的核心开发人员)的 DoctrineExtensions 实现.在doctrine2 中,您可以通过扩展functionNode 类来定义您自己的查询表达式.
Yes this is possible with DoctrineExtensions from Beberlei (a core developer of Doctrine2). In doctrine2 you can define your own query expressions by extending the functionNode class.
最简单的方法是在您的项目中包含 DoctrineExtensions 库.我不知道您使用的是 Zend Framework 还是 Symfony 或任何其他框架,因此无法帮助您嵌入它.
The easiest way is to include the DoctrineExtensions lib in your project. I don't know wether your are using Zend Framework or Symfony or any other framework so can't help you with embedding it.
您可以在此处查看 DoctrineExtensions:
You can checkout DoctrineExtensions here:
https://github.com/beberlei/DoctrineExtensions
还有群功能:
https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/GroupConcat.php
请注意,您应该使用 GroupConcat 作为函数名,而不是像 MySQL 中那样使用 GROUP_CONCAT.
Be aware you should use GroupConcat as function name not GROUP_CONCAT like in MySQL.
希望对你有帮助!
这篇关于学说2和group_concat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)