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

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

    $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
  }
}

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

studio2079 回答:如何在具有联接表的Doctrine结果中更改数组结果层次结构

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

键“联接表”不会出现,但您将根据实体获得数据结构。

本文链接:https://www.f2er.com/3167227.html

大家都在问