doctrine2 and group_concat(学说2和group_concat)
问题描述
我一直在浏览文档/谷歌,但没有找到任何解决方案.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:学说2和group_concat
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
