Symfony2 - CreateBuilder - 在其他查询中查询

时间:2012-08-09 16:07:55

标签: sql symfony doctrine

我们如何在Symfony 2中使用doctrine执行此查询:

SQL:

SELECT p.* FROM messages, (SELECT * from posts ORDER BY created_at DESC) as p GROUP BY p.category_id ORDER BY message.created_at;

问题:每个表都必须是像MyProjectMyBundle这样的实体:MyEntity,(SELECT *来自帖子ORDER BY created_at DESC)不是实体......

Symfony 2(不起作用):

$query = $em->createQuery('SELECT p.* 
              FROM MyProjectMyBundle:Messages, 
              (SELECT * from posts ORDER BY created_at DESC) as p 
              GROUP BY p.category_id ORDER BY message.createdAt');

我们可以包含像Mysql这样的其他查询吗?一个解决方案?

由于

1 个答案:

答案 0 :(得分:1)

我相信Doctrine不允许你在From语句中创建子查询。但是,您可以将常规sql键入doctrine。

以下是关于此问题的帖子:Using Raw SQL with Doctrine