Ticket #1381 (closed defect: worksforme)
Calculated columns don't live well with Identity Map
| Reported by: | francois | Owned by: | jwage |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | Attributes | Version: | 0.11.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | no |
Description
When adding custom columns to the SELECT part of a DQL statement, Doctrine makes these columns available as property of the object they are related to.
Here is a DQL example:
//Article has many Comments
SELECT c.*, a.title ArticleTitle FROM Comment c INNER JOIN c.Article a LIMIT 1
// will hydrate a Comment object looking like
-
id: 123
body: I completely agree
article_id: 456
Article:
id: ~
title: ~
body: ~
ArticleTitle: Hello, world
So that works, since I can retrieve my custom ArticleTitle column by calling $comment['Article']['ArticleTitle'].
But if I already queried this Article or this Comment objects, IdentityMap? enters the dance, and the result of the query is:
-
id: 123
body: I completely agree
article_id: 456
Article:
id: 456
title: Hello, World
body: Lorem Ipsum...
The bad news is that I can no longer access my custom column by its alias: $comment['Article']['ArticleTitle'] doesn't work.
This probably means that IdentityMap? should be deactivated on queries where custom columns are added. I don't know if there is a way to do that, all I could find was to clear the identity map prior to executing the query:
Doctrine::getTable('Article')->clear();
Doctrine::getTable('Comment')->clear();
This is less than ideal, and should be handled by Doctrine rather than by the user...