教学选择与subselect返回水合物体

时间:2017-10-23 16:20:44

标签: symfony doctrine-orm dql

我想进行如下查询:

$qbFoo = $this->createQueryBuilder('foo');
$qbFoo->where($qbFoo->expr()-eq('foo.field', $value));

$qbProduct = $this->createQueryBuilder('product');
$qbProduct->select(['product'])
          ->addSelect(sprintf('(%s) as foo', $qbFoo->getDQL()))
          ->where($qbProduct->expr()->eq('product.id', $prodId));

$result = $qbProduct->getQuery()->getResult();

$ result的值将是:

$result[0][0] = {AppBundle\Entity\Product}
$result[0]['foo'] = 6      (6 is the value of foo.id)

我怎样才能得到$结果:

$result[0][0] = {AppBundle\Entity\Product}
$result[0]['foo'] = {AppBundle\Entity\Foo}

0 个答案:

没有答案