Symfony:连接两个表以获取单独列中的值时出错


Symfony: error while joining 2 tables to fetch values in seperate columns

我想从一个名为"sales"的表中获取3个值,从一个名称为"products"的表格中获取1个值,我写了以下DQL:

$repo = $em->getRepository('SystemBundle:Sales');
        $q = $repo->createQueryBuilder('s')
            ->select('s.units','s.timestamp','p.price')
            ->join('SystemBundle:Product', 'p')
            ->where('s.prodId = p.id AND p.company=:comp')
            ->setParameter('comp', $cid)
            ->getQuery()
            ->getArrayResult();
        return new JsonResponse($q);

但我得到了这个错误:

[语义错误]"SystemBundle:Product"附近的第0行第81列:错误:未定义类"SystemBundle ''Entity''Product"。

这是我第一次使用join-in原则,所以我想我在这里搞砸了语法。。请帮助解决这个

感谢

使用条令方法,您可以获取所需的结果:

$productRepository = $em->getRepository('SystemBundle:Product');
$oProduct = $productRepository->findBy(array('company' => $cid));
$oCompany = $oProduct->getCompany();
$result = array(
    'units' => $oCompany->getUnits(),
    'timestamp' => $oCompany->getTimestamp(),
    'price' => $oProduct->getPrice(),
);
$response = new JsonResponse();
$response->setData($result);
return $response;