views:

90

answers:

2

Hello,

On my application, i frequently do doctrine query like this :

$coms = Doctrine_Core::getTable('Comment')
->createQuery('c')
->join('c.article a')
->join('a.Writter w')
->where('w.something = ?', $something); 

I want to extract the comments from articles with a condition on the writter. Le query start from the Comment Table ( because finally, we want a doctrine collection of Comment ), next i join to all the articles and then to all the writters. Finally, i make a restriction with the condition on the writters.

This query could be more optimized with the joints in this order :

$coms = Doctrine_Core::getTable('Writter')
->createQuery('w')
->select('c.*')
->join('w.Article a')
->join('a.Comments c')
->where('w.something= ?', $something); 

Like this, the number of lines manipulated by the joints is much more reduced., because the restriction on the writter is made at first.

But with this code, i got an error :

The root class of the query (alias w) must have at least one field selected.

Does a solution exist to keep this order in joints and obtain finally a doctrine collection of Comment ?

Merci !

A: 

Hi,

no there is no other solution than to keep your first query. You always get a collection of object of the root class you choose by using getTable('xyz'). There is no way around this.

Timo