Doctrine2使用不同的表加入Native查询

时间:2012-09-11 17:31:02

标签: php mysql join doctrine-orm

大家好,我坚持使用Doctrine连接查询。

系统继续告诉我拍卖没有映射:

Class Auction does not exist and could not be loaded in Doctrine/doctrine-orm/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php on line 40

显然,该项目已经开启,并且其他联接也成功使用。

include_once '../../../bootstrap_doctrine.php';

$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('Auction', 'Au');
$rsm->addEntityResult('VariantPerAuction', 'Vpa');

$Q=" SELECT Au.id
FROM Auction Au
JOIN VariantPerAuction Vpa ";
        $query = $entityManager->createNativeQuery($Q,$rsm);

$auctions = $query->getResult();

1 个答案:

答案 0 :(得分:1)

感谢Marco Pivetta,它现在似乎有效。

问题似乎是Doctrine2 Class没有完全命名空间。

快速试用完全命名它们的作用。

在每个班级之上:

// put the folder where your class is
 namespace DbClasses\entities;

新的加入查询变为:

$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('DbClasses\entities\Auction', 'Au');
$rsm->addEntityResult('DbClasses\entities\VariantPerAuction', 'Vpa');

$Q=" SELECT Au.id
FROM Auction Au
JOIN VariantPerAuction Vpa 
Where Au.piattaforma='EbayDE' AND Au.OggettoEbayDBContainer_id=159";

$auctions = $query->getResult();