giuseppe
giuseppe

Reputation: 907

Doctrine2 Join Native query with different tables

Hello everybody, I'm stuck with a Doctrine join query.

The system continues telling me that Auction is not mapped:

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

The project is already on, obviously, and also other joins were used with success.

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

Upvotes: 0

Views: 1798

Answers (1)

giuseppe
giuseppe

Reputation: 907

Thanks to Marco Pivetta, it now seems to work.

The problem seems to be that Doctrine2 Class weren't fully namespaced.

A fast trial fully namespacing them works.

On top of each class:

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

The new Join Query becomes:

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

Upvotes: 1

Related Questions