教义2左加入产生意想不到的结果


Doctrine2 LEFT JOIN WITH producing unexpected result

我有以下查询:

<?php
$em = $this->getDoctrine()->getManager();
$data['ps'] = $em->createQuery('SELECT s,ps FROM AppBundle:Sucursales s LEFT JOIN AppBundle:ComprasProductosSucursales ps WITH s.id = ps.sucursal')->getResult();

但是我得到的结果如下图所示:

![教义示例2结果集][1]

我希望$data['ps'][1]成为$data['ps'][0]的一部分,否则数组的迭代将非常奇怪。

那么,是否可以将联接表 AppBundle:ComprasProductosSucursales 的结果作为 AppBundle:Sucursales 数据的列?

ORMs:

AppBundle'Entity'Sucursales:
    type: entity
    table: sucursales
# Note: no relations defined, deleting the rest of the columns for clarity
AppBundle'Entity'ComprasProductosSucursales:
    type: entity
    table: compras_productos_sucursales
manyToOne:
    producto:
        targetEntity: ComprasProductos
    sucursal:
        targetEntity: Sucursales
        cascade: {  }

假设您有相关的实体,那么通常您的 DQL 查询如下所示:

  $dql <<<EOT
SELECT s,ps FROM AppBundle:Sucursales s 
LEFT JOIN s.ps ps
EOT;

Doctrine 负责连接上的 with 条件,并会为您提供一组嵌套的结果。 假设您的 Sucursales 具有一个名为 ps 的集合属性。 我想我也假设您正在创建教义 2 实体并将它们相关联。

更多信息: http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html#joins