Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3091

Not set entity to results if use query with JOIN

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None

      Description

      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:

      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

      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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Vitaliy Zhuk
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: