在学说 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
相关文章