Damien Romito
Damien Romito

Reputation: 10055

Symfony2 - CreateBuilder - Query in other Query

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

Upvotes: 1

Views: 779

Answers (1)

NightRaven
NightRaven

Reputation: 401

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

Upvotes: 1

Related Questions