2016-05-13 19 views
1

私は「製品」という名前のテーブルからテーブル名「販売」と1から3つの値、2を取得したいが、私はDQL以下の書いた:symfonyの:エラー別々の列の値を取得するために2つのテーブルを結合しながら

$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); 

が、私はこのエラーを取得しています:

[Semantical Error] line 0, col 81 near 'SystemBundle:Product': Error: Class 'SystemBundle\Entity\Product' is not defined.

それはでの作業私の最初の時間は、教義に参加するので、私は、私はここに構文をいじってい推測する。これ

感謝

を解決する助けてください教義の方法では
+0

を売上高は、製品に関係がありますか?もしそうなら、結合は ' - > join(' s.products '、' p ');'ここで、「products」はリレーション名として設定した名前です。どこのprodId = id部分をスキップする必要があります – JimL

+0

なぜ教訓で結果を取得しませんでしたか? –

答えて

1

あなたが必要な結果フェッチすることができます

$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; 
関連する問題