Ticket #1380 (closed defect: fixed)
Lack of a clear way to access calculated DQL columns
| Reported by: | francois | Owned by: | jwage |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.0.3 |
| Component: | Attributes | Version: | 1.0.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | no |
Description
When adding calculated DQL columns, Doctrine tries to find a way to make it available from the base record, but can't figure out what to do when the calculation is on several objects.
Here is a DQL example:
//Article has many Comments
SELECT a.*, COUNT(a.Comment) NbComment FROM Article a GROUP BY a.id LIMIT 1
// will hydrate an Article object looking like
-
id: 456
title: Hello, world
body: Lorem Ipsum...
Comment:
id: ~
body: ~
article_id: ~
NbComment: 23
So that works, since I can retrieve my custom NbComment column by calling $article['Comment']['NbComment'].
But when the calculation is on more than one class, the hydrator has no way to determine where to attach the new column.
Since the current behavior is not very intuitive and very limited, I suggest that calculated columns should be made available directly to the base record - providing they have an alias, which should be compulsory. That way, using the previous DQL statement, the alias NbComments could be retrieved by calling $article['NbComment'].