DDC-3091: Not set entity to results if use query with JOIN #3866

Open
doctrinebot opened this Issue Apr 17, 2014 · 0 comments

2 participants

@doctrinebot

Jira issue originally created by user zhukv:

Hi.
I have a problem, if i can use query with JOIN* without grouping (DISTINCT) by identifier entity. Problem: not set entities to result, if entity has cached in *ObjectHydration.

For example:

SQL query:

SELECT 
  b0_.id AS id0,
  b0_.hash AS hash1, 
  b0_.mii AS mii2, 
  b0_.iin AS iin3, 
  b0*.last_digits AS last*digits4, 
  b0_.number AS number5, 
  b0_.holder AS holder6, 
  p1_.keyword AS keyword7, 
  t2_.client AS client8, 
  CONCAT(b0*.hash, CONCAT(p1_.keyword, t2*.client)) AS sclr9 

FROM bank*card b0* 
  INNER JOIN transaction*bank_card t2_ ON (t2_.bank_card_id = b0*.id) 
  INNER JOIN projects p1* ON (t2_.project_key = p1*.keyword) 

WHERE (p1*.keyword = 'project1' AND t2_.client = '123') OR (p1_.keyword = 'project2' AND t2*.client = '321') /** ... Other where **/

GROUP BY sclr9

Mysql result:

{quote}
| id0 | hash1 | mii2 | iin3 | last_digits4 | number5 | holder6 | keyword7 | client8 | sclr9 |
| 28 | 1d741fd06f3315dad28039926effc5d7 | 5 | 533330 | 2763 | 533330*****2763 | John Doe | p6 | 78165 | 1d741fd06f3315dad28039926effc5d7p678165 |
| 34 | 58b021876f625e3000137cd835f5fe40 | 5 | 555456 | 5047 | 555456
**5047 | OLOLO OLOLO | p6 | 78165 | 58b021876f625e3000137cd835f5fe40p678165 |
| 2 | 887d30e9b4d18676c6e0dc8e21e36d28 | 5 | 556458 | 4251 | 556458
**4251 | Monkey Testing | p6 | 78165 | 887d30e9b4d18676c6e0dc8e21e36d28p678165 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 100673 | bb14a77f2e363cd144b669f0b594d304p6100673 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 100922 | bb14a77f2e363cd144b669f0b594d304p6100922 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 101441 | bb14a77f2e363cd144b669f0b594d304p6101441 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 78165 | bb14a77f2e363cd144b669f0b594d304p678165 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 85550 | bb14a77f2e363cd144b669f0b594d304p685550 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
**1118 | Monkey Testing | p6 | 85566 | bb14a77f2e363cd144b669f0b594d304p685566 |
| 1 | bb14a77f2e363cd144b669f0b594d304 | 4 | 432114 | 1118 | 432114
*****1118 | Monkey Testing | p6 | 85768 | bb14a77f2e363cd144b669f0b594d304p685768 |
{quote}

And the PHP code (from custom entity repository):

$qb
            ->select('bc')
            ->addSelect('p.key AS project_key')
            ->addSelect('tbc.client AS client')
            ->addSelect('CONCAT(bc.hash, CONCAT(p.key, tbc.client)) AS unique_key')
            ->innerJoin('FooBundle:TransactionBankCard', 'tbc', 'WITH', 'tbc.bankCard = bc.id')
            ->innerJoin('BarBundle:Project', 'p', 'WITH', 'tbc.project = p.key')
            ->where($orX)
            ->groupBy('unique_key');

        $result = $qb->getQuery()->getResult();

And this code returned only unique entities by identifier (Identifier: id field), but must returned the all entities from query.

The Object Hyndration has cached created entities, and if the next row is entity (indicate as identifier and dql alias), then hydration not set this entity to result.
Problem code: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L569-L572

Thank.

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment