Aliasing fields using partial object syntax + array hydrator in doctrine 2(在学说 2 中使用部分对象语法 + 数组水合器为字段别名)
问题描述
在使用 在 Doctrine 2 中的部分对象语法?
我知道我能做到:
$this->createQueryBuilder('user')->select([
'user.id AS id',
'user.firstName AS first_name',
'user.lastName AS last_name',
'user.email AS email',
'user.dateCreated AS date_created'
])->getQuery()->getArrayResult();
但是我需要使用部分对象语法,以便学说在嵌套的关系层次结构中检索结果:
However I need to use the partial object syntax in order for doctrine to retrieve the result in a nested relational heirarchy:
$this->createQueryBuilder('team')
->select('PARTIAL team.{id, name, dateCreated}, s, PARTIAL e.{id, name}')
->innerJoin('team.session', 's')
->innerJoin('s.event', 'e')
->getQuery()->getArrayResult();
我在 DoctrineORMInternalHydrationArrayHydrator
中进行了挖掘,但没有看到任何钩子或任何东西,而且看起来 Doctrine 没有 postSelect
事件或可以让我实现自己的突变的东西.
I dug around in DoctrineORMInternalHydrationArrayHydrator
but didn't see any hooks or anything, and it doesn't look like Doctrine has a postSelect
event or something that would allow me to implement my own mutation.
感谢您的帮助!
推荐答案
效率不是很高,但我最终解决了 继承 ArrayHydrator 并自己改变键.
Not very efficient, but I ended up subclassing the ArrayHydrator and mutating the keys myself.
希望有更好的方法,如果没有,我希望这对某人有所帮助
Hopefully there is a better way, if not I hope this helps someone
这篇关于在学说 2 中使用部分对象语法 + 数组水合器为字段别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在学说 2 中使用部分对象语法 + 数组水合器为字段别名
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01