沃梦达 / 编程问答 / php问题 / 正文

在学说 2 中使用部分对象语法 + 数组水合器为字段别名

Aliasing fields using partial object syntax + array hydrator in doctrine 2(在学说 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 中使用部分对象语法 + 数组水合器为字段别名

基础教程推荐