我有一个Doctrine查询,其中“JOIN p.product pr”正在加入产品表及其所有信息(id,name,qty,status,created,updated,deletedAt等等)< / p>
我的存储库类中的自定义函数...
$query = $this->getEntityManager()
->createQuery('
SELECT p
FROM WIC\PurchaseOrderBundle\Entity\PurchaseOrderProductsStatus p
JOIN p.product pr
WHERE p.inventoryLocation = :id
AND p.account = :account_id')
->setParameter('id', $id)
->setParameter('account_id', $account_id);
try{
return $query->getArrayResult();
}catch (\Doctrine\ORM\NoResultException $e) {
return $e;
}
在我的控制器中,我将数组发送到树枝模板中......
$productActions = My custom function query listed above which returns array
return array(
'heading' => 'Inventory Staging Location',
'productActions' => $productActions,
);
在我的Twig模板中,我现在正试图遍历记录......
{% for productAction in productActions %}
<tr>
<td>{{ productAction.product.sku }}</td>
<td>{{ productAction.product.name }}</td>
<td></td>
</tr>
{% endfor %}
我收到此错误...
Key "product" for array with keys "id, qty, status, created, updated, deletedAt" does not exist in ...
我做错了什么?
当我通过执行 - &gt; findBy()进行查询时,一切似乎都正常。 此数组在发送到树枝模板
时有效 $productActions = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrderProductsStatus')->findBy(array(
"inventoryLocation"=>$inventoryLocation,
"account"=>$account_id,
));
谢谢!
答案 0 :(得分:1)
您需要在SELECT部分中请求 pr ;)
$query = $this->getEntityManager()
->createQuery('
SELECT p, pr
FROM WIC\PurchaseOrderBundle\Entity\PurchaseOrderProductsStatus p
JOIN p.product pr
WHERE p.inventoryLocation = :id
AND p.account = :account_id')
->setParameter('id', $id)
->setParameter('account_id', $account_id);
try{
return $query->getArrayResult();
}catch (\Doctrine\ORM\NoResultException $e) {
return $e;
}