这就是我得到的:
$queryBuilder = $this->createQueryBuilder('a')->select()->where('a.id = ?0')->setParameters(array($id));
$queryBuilder->leftJoin('Doctrine\Entity\AccommodationUser', 'b');
$queryBuilder->leftJoin('Doctrine\Entity\AccommodationContact', 'c');
这不会工作,我得到:[语法错误]第0行,第97行:错误:预期文字,得到了“加入”#39;错误信息。但如果我尝试一个一个地做到这一点
$queryBuilder = $this->createQueryBuilder('a')->select()->where('a.id = ?0')->setParameters(array($id));
$queryBuilder->leftJoin('Doctrine\Entity\AccommodationContact', 'c');
或
$queryBuilder = $this->createQueryBuilder('a')->select()->where('a.id = ?0')->setParameters(array($id));
$queryBuilder->leftJoin('Doctrine\Entity\AccommodationUser', 'b');
它确实有用!
答案 0 :(得分:2)
$ queryBuilder-> leftJoin('a。 nameOfPropertyInAEntity ','b');
答案 1 :(得分:1)
Doctrine并没有在join语句中使用类名。如果您想加入另一个表格,则需要使用表格WITH src
AS (SELECT DISTINCT i.id,
iwt.wearlocid,
i.sdesc,
i.wearprog,
i.isoog,
i.minlvl,
i.maxlvl
FROM item i
inner join itemweartable iwt
ON i.id = iwt.itemid
WHERE iwt.wearlocid >= 1
AND iwt.wearlocid <= 22
AND i.minlvl <= 50)
SELECT DISTINCT src.id,
src.wearlocid,
src.sdesc,
src.wearprog,
src.isoog,
src.minlvl,
src.maxlvl,
iaft.affectid,
iaft.amount,
NULL AS affectbyID
FROM src
left join itemaffecttable iaft
ON src.id = iaft.itemid
UNION ALL
SELECT DISTINCT src.id,
src.wearlocid,
src.sdesc,
src.wearprog,
src.isoog,
src.minlvl,
src.maxlvl,
NULL AS affectID,
NULL AS amount,
iafbt.affectbyid
FROM src
left join itemaffectedbytable iafbt
ON src.id = iafbt.itemid
ORDER BY wearlocid,
sdesc,
id
alias.property