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 中使用部分对象语法 + 数组水合器为字段别名
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
