我正在尝试使用Doctrine2 QueryBuilder类执行嵌套查询,该类执行类似于此正常Sql查询的操作:
SELECT e.name, c.name
FROM
employee AS e
LEFT JOIN
(task as t
INNER JOIN customer AS c
ON t.id = c.task_id)
ON e.id = t.employee_id
有没有办法在Symfony / Doctrine中嵌套JOIN子句?
答案 0 :(得分:0)
有时使用queryBuilder或queryLanguage构建查询有点困难。在这种情况下,我通常使用纯PDO语法来获取我的记录。这是我older answer这样的任务..
我还在这里包含示例代码:
public function fetchSomeRecordFromMyTable()
{
$sql = 'MY PURE MYSQl QUERY';
$connection = $this->getEntityManager()->getConnection()->prepare($sql);
$connection->execute();
return $connection->fetchAll(\PDO::FETCH_ASSOC);
}