如何在具有连接表的Doctrine结果中更改数组结果层次结构

问题描述 投票:0回答:1

我的联接查询:(在实体中不是关系)

    $query = $this
        ->createQueryBuilder('f')
        ->select('f');

    $query->leftJoin(IntranetType::class, 'it', 'WITH', 'it.flyerLayoutType = f.flyerLayout');
    $query->addSelect('it');

    $query->orderBy('f.filename');
    $query->addOrderBy('it.flyerLayoutType');

    // $flyers = $query->getQuery()->getArrayResult(); <-- fist try
    $flyers = $query->getQuery()->getResult(Query::HYDRATE_ARRAY);

结果数组的格式为:

array(149) {
[0]=>
array(9) {
 data from table with alias f
}
[1]=>
array(4) {
 data from table with alias it
}
[2]=>
array(9) {
 data from table with alias f
}
[3]=>
array(4) {
 data from table with alias it
}

但是我需要这样的格式:

array(149) {
[0]=>
array(9) {
 data from table with alias f
  ['joined table']=>
  array(4) {
   data from table with alias it
  }
}

[1]=>
array(9) {
 data from table with alias f
  ['joined table']=>
  array(4) {
   data from table with alias it
  }
}

仅层次结构...数组中的一键=一张传单(一件),并且具有连接的数据...

php sql symfony multidimensional-array doctrine
1个回答
0
投票

似乎您只需要从getResult()中删除参数(或将其替换为默认的::HYDRATE_OBJECT)。

键'joined table'不会出现,但您将根据实体获得数据结构。

© www.soinside.com 2019 - 2024. All rights reserved.