简体   繁体   English

如何从二维数组中的查询构建器获取 doctrine 实体?

[英]How is it possible to get doctrine entities from a query builder in a 2D array?

I created a query, with multiple entities selected:我创建了一个查询,选择了多个实体:

$qb->select(['user', 'unit'])

If I call $qb->getQuery()->getResult() , I get an array, like this:如果我调用$qb->getQuery()->getResult() ,我会得到一个数组,如下所示:

[ Entity\User, Entity\Unit, Entity\User, Entity\Unit, ... ]

But I would like to get the result in this format:但我想以这种格式得到结果:

[ [ Entity\User, Entity\Unit ], [ Entity\User, Entity\Unit ], ... ]

How is it possible?这怎么可能? I was not able to find anything in the doctrine Query documentation我在doctrine 查询文档中找不到任何内容


I could use array_chunk($result, 2) , but I am not sure that it will work in all cases.我可以使用array_chunk($result, 2) ,但我不确定它是否适用于所有情况。 For example what if one unit is null.例如,如果一个unit是 null。 Doctrine skips it, or it just inserts a null into the list? Doctrine 跳过它,或者它只是将 null 插入到列表中? I am not able to find detailed information about the getResult function.我无法找到有关getResult function 的详细信息。

Assuming that "user" and "unit" has no direct relationship or need to be fetched entirely together then you should group them using a custom class handler假设“用户”和“单位”没有直接关系或需要完全一起获取,那么您应该使用自定义 class 处理程序对它们进行分组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM