Details
Description
My case is the follwing :
In a range of dates, I want to know if an entity has been defined for each day. So the raw SQL result would looks like :
DATE ID NAME --------- ---------- ------------- 19-SEP-11 4 [Entity Name] 20-SEP-11 1 [Entity Name] 21-SEP-11 2 [Entity Name] 22-SEP-11 3 [Entity Name] 23-SEP-11 NULL NULL 24-SEP-11 NULL NULL 25-SEP-11 NULL NULL 26-SEP-11 NULL NULL 27-SEP-11 7 [Entity Name] 28-SEP-11 6 [Entity Name] 29-SEP-11 5 [Entity Name] 11 rows selected.
The range calculation forced me to use Native Query, but I stumbled upon a strange behavior : the Result array showed less records than the raw SQL would provide. After some dirty debugging, I found out that during hydration, an array of previously hydrated object keys was stored ObjectHydrator->_identifierMap. The key of null elements (the gap in the SQL result above) is stored too. The problem is that when there is multiple empty elements, hydration only keeps one, and forget the others, thus reducing the overall size of the output result.
I've already come up with a quick n'dirty fix wich suits my current needs, but it would be better if this issue was addressed at a more global level.
Here's the one-liner fix :
if ( ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]]) ) {
if ( ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]]) || str_replace( '|', '', $id[$dqlAlias]) == '') {
Doesnt he still hydrate an empty object for this row then? Why are you even using the object hydrator? I rather tend to go and throw an exception if for a query using the ObjectHydrator $id[$dqlAlias] is empty, because frankly this is just not supported.