Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3084

Native query removes duplicate root entities

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      I have a query like that:

              $rsm = new ResultSetMappingBuilder($this->_em);
              $rsm->addScalarResult('rank', 'rank');
              $rsm->addRootEntityFromClassMetadata('Application\Entity', 'e');
      
      		$query = $this->_em->createNativeQuery('
                  SELECT
                  	r.rank, ' . $rsm->generateSelectClause(array('e')) . '
                  FROM ...
      	    ', $rsm);
      
              return $query->getResult();
      

      When I issue it at the mysql side it returns 3 rows but doctrine returns only 2 - I have tried getArrayResults() with the same results

      The query could return the same entity multiple times for different values of the "rank" scalar value but it seems that doctrine removes those duplicates

        Activity

        Hide
        Przemyslaw Wrobel added a comment -

        the result should be like this: ("rank", "entity")
        1, entity1
        2, entity2
        3, entity2

        Show
        Przemyslaw Wrobel added a comment - the result should be like this: ("rank", "entity") 1, entity1 2, entity2 3, entity2
        Hide
        Marco Pivetta added a comment -

        Doctrine ORM groups the values of the root of the selection by identifier during hydration: this is the expected result.

        Show
        Marco Pivetta added a comment - Doctrine ORM groups the values of the root of the selection by identifier during hydration: this is the expected result.
        Hide
        Przemyslaw Wrobel added a comment -

        If it is really grouping than I shoud have something like that
        entity1, 1
        entity2, array(2,3)

        Now the problem is that I am losing data - the row: 3, entity2 is missing and I have to resort to DBAL query or do not map to entities but than I cannot use my model logic

        Show
        Przemyslaw Wrobel added a comment - If it is really grouping than I shoud have something like that entity1, 1 entity2, array(2,3) Now the problem is that I am losing data - the row: 3, entity2 is missing and I have to resort to DBAL query or do not map to entities but than I cannot use my model logic
        Hide
        Marco Pivetta added a comment -

        The resultset you proposed doesn't make sense to me, as it contains inhomogeneous data.

        I'd just suggest skipping over adding a root entity to the RSM.

        Show
        Marco Pivetta added a comment - The resultset you proposed doesn't make sense to me, as it contains inhomogeneous data. I'd just suggest skipping over adding a root entity to the RSM.
        Hide
        Francisco Facioni added a comment -

        How do you hydrate the entities without setting a root entity to the RSM?

        Show
        Francisco Facioni added a comment - How do you hydrate the entities without setting a root entity to the RSM?
        Hide
        Francisco Facioni added a comment -

        It looks like there is some commented code that would fix this issue => https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L569

        Show
        Francisco Facioni added a comment - It looks like there is some commented code that would fix this issue => https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L569

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Przemyslaw Wrobel
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: