Symfony2查询生成器不返回内部联接数据


Symfony2 query builder does not return inner join data

我使用Symfony2和Doctrine,我的存储库中有这段代码。

$cb = $this->getEntityManager() ->createQueryBuilder("p") ->select($arrayColumns) //This array contains the fields ->from('MainBundle'Entity'Pedido', 'p') ->innerJoin('p.sucursal', 's');

$arrayColumns包含以下内容:['.fecha','s.description','p.description','sp.id']。当执行此查询时,结果包含:['.fecha','p.description','p.id']。它省略了'sucursal'字段。Sucursal和Pedido之间的关系是OneToMany。

也许您应该用纯SQL构建查询,并使用RSM映射实体。

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/native-sql.html#resultsetmappingbuilder

您可能需要使用:

$arrayColumns[] = "IDENTITY(p.sucursal)";

在查询之前

如下所述:https://github.com/doctrine/doctrine2/issues/1955在这里:http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html