Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.2
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
I'm trying to run a query that gets a forum, its threads and the number of replies for each thread. The following query works as per the documentation:
$threads = Doctrine_Query::create()
->select('p.*, COUNT(c.id) as num_replies)
->from('Posts p')
->leftJoin('p.Children c')
->where('p.parent_id IS NULL')
->groupBy('p.id')
->fetchArray(array(), Doctrine_Core::HYDRATE_ARRAY);
As expected, I can access $threads[0]['num_replies'] and I get the COUNT() of the number of children for the thread.
However, when I run this query:
$forum = Doctrine_Query::create()
->select('f., p., COUNT(c.id) as num_replies)
->from('Forum f')
->leftJoin('f.Posts p WITH p.parent_id IS NULL')
->leftJoin('p.Children c')
->where('f.slug = ?', $params[0])
->groupBy('p.id')
->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
Instead of num_replies being assigned to each Posts[] object, it is only being assigned once to the Forum object, rendering it totally useless.