1

How can we execute this query with doctrine in Symfony 2:

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;

Probleme: Every table must be an Entity like MyProjectMyBundle:MyEntity, (SELECT * from posts ORDER BY created_at DESC) is not an Entity...

Symfony 2 (doesnt work):

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

Can we include an other query like Mysql? A solution?

Thanks

Damien Romito
  • 9,801
  • 13
  • 66
  • 84

1 Answers1

1

I believe Doctrine does not allow you to make subqueries inside the From statement. However, you can type regular sql into doctrine.

Here is a post on this: Using Raw SQL with Doctrine

Community
  • 1
  • 1
NightRaven
  • 401
  • 3
  • 17
  • Thanks. A good way to keep Entities with a native SQL Query: http://sf2.memosdedev.com/creer-une-requete-sql-native-dans-symfony2-avec-doctrine2.html – Damien Romito Aug 10 '12 at 08:13