Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.2.3
-
Fix Version/s: None
-
Component/s: Documentation
-
Labels:None
Description
In the documentation for using aggregate values with Doctrine Query (link below), there is a code snippet that shows how to access the value of the aggregate field, which does not work.
The code snippet is:
//firstsnippet after header
$q = Doctrine_Query::create()
->select('u.id, COUNT(t.id) AS num_threads')
->from('User u, u.Threads t')
->where('u.id = ?', 1)
->groupBy('u.id');
//second snippet after header
$users = $q->execute();
//fourth snippet after header
echo $users->num_threads . ' threads found';
The code from the last snippet for accessing the count value, $users->num_threads, doesn't seem to work. What does work for me is:
//access count value
echo $users[0]->num_threads
//My exact code is:
$query = Doctrine_Query::create()
->select('COUNT
as batchCount')
->from('Batch');
$result = $query->execute();
echo $result->batchCount; //10
echo $result[0]->batchCount; //3 (3 is correct, from direct MySQL command line query)
It's certainly possible I'm doing something wrong, or that there is a Doctrine_Core attribute I need to set. If there is a Doctrine_Core attribute to set to automatically access aggregate values from the Collection, it would be worth noting at the top of the section.
Thanks, and thanks for Doctrine (so awesome).
Activity
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-872, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)