I have four entities: OfficialDocument
, Media
, NMediaStatus
and NMediaType
. I'm trying to translate this SQL:
SELECT od.media, od.type, od.status, md.url, nms.name
FROM official_document od
LEFT JOIN media md ON od.media = md.id
LEFT JOIN n_media_status nms ON od.status = nms.id
WHERE od.company = 9
to Doctrine Query Builder and this is the result:
public function findOfficialDocument($company_id) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('od.media', 'od.type', 'od.status', 'md.url', 'nms.name', 'nmt.name');
$qb->from('CompanyRegisterCompanyBundleEntityOfficialDocument', 'od');
$qb->leftJoin('CommonMediaBundleEntityMedia', 'md', DoctrineORMQueryExprJoin::WITH, 'od.media = md.id');
$qb->leftJoin('CommonMediaBundleEntityNMediaStatus', 'nms', DoctrineORMQueryExprJoin::WITH, 'od.status = nms.id');
$qb->leftJoin('CommonMediaBundleEntityNMediaType', 'nmt', DoctrineORMQueryExprJoin::WITH, 'od.type = nmt.id');
$qb->where('od.company = ?1');
$qb->setParameter(1, $company_id);
return $qb->getQuery()->getResult();
}
But any time I call the function from my controller I get this error:
[Semantical Error] line 0, col 10 near 'media, od.type,': Error:
Invalid PathExpression. Must be a StateFieldPathExpression.
[1/2] QueryException: SELECT od.media, od.type, od.status, md.url,
nms.name, nmt.name FROM
CompanyRegisterCompanyBundleEntityOfficialDocument od LEFT JOIN
CommonMediaBundleEntityMedia md WITH od.media = md.id LEFT JOIN
CommonMediaBundleEntityNMediaStatus nms WITH od.status = nms.id
LEFT JOIN CommonMediaBundleEntityNMediaType nmt WITH od.type =
nmt.id WHERE od.company = ?1
OfficialDocument
is related to the other three entities, but since I don't need the reversedBy
in those entities then I tough this is causing the error, or maybe not, not sure about it. Anyway, any advice or help to fix this issue?
PS: I'm using latest Symfony2 and Doctrine2 if you need to take a look to my entities here they are: OfficialDocument, Media, NMediaStatus, NMediaType
See Question&Answers more detail:
os