Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1819

Allow ResultSetMapping to be used for objects that are not entities

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None

      Description

      Currently Doctrine\ORM\Query\ResultSetMapping can only be used to query the database for entities using the EntityManager::createNativeQuery method. It would be great if we could use this as well for objects that are not entities. That way we can create simple DTO's and map them to a query using the ResultSetMapping.

      I'll open a PR If there are no objections.

        Activity

        Marijn Huizendveld created issue -
        Marijn Huizendveld made changes -
        Field Original Value New Value
        Description Currently `Doctrine\ORM\Query\ResultSetMapping` can only be used to query the database for entities using the `EntityManager::createNativeQuery` method. It would be great if we could use this as well for objects that are not entities. That way we can create simple DTO's and map them to a query using the `ResultSetMapping`.

        I'll open a PR If there are no objections.
        Currently {{Doctrine\ORM\Query\ResultSetMapping}} can only be used to query the database for entities using the {{EntityManager::createNativeQuery}} method. It would be great if we could use this as well for objects that are not entities. That way we can create simple DTO's and map them to a query using the {{ResultSetMapping{{.

        I'll open a PR If there are no objections.
        Hide
        Benjamin Eberlei added a comment -

        Good idea. You could make this happen by adding a ArbitraryObjectHydrator that does not use the ClassMetadata but creates ReflectionProperty instances during the hydration.

        Api would then be:

        $rsm = new ResultSetMapping();
        ....
        
        $query = $em->createNativeQuery($sql, $rsm);
        $objects = $query->getResult(Query::HYDRATOR_ARBITRARY_OBJECTS);
        
        Show
        Benjamin Eberlei added a comment - Good idea. You could make this happen by adding a ArbitraryObjectHydrator that does not use the ClassMetadata but creates ReflectionProperty instances during the hydration. Api would then be: $rsm = new ResultSetMapping(); .... $query = $em->createNativeQuery($sql, $rsm); $objects = $query->getResult(Query::HYDRATOR_ARBITRARY_OBJECTS);
        Marijn Huizendveld made changes -
        Description Currently {{Doctrine\ORM\Query\ResultSetMapping}} can only be used to query the database for entities using the {{EntityManager::createNativeQuery}} method. It would be great if we could use this as well for objects that are not entities. That way we can create simple DTO's and map them to a query using the {{ResultSetMapping{{.

        I'll open a PR If there are no objections.
        Currently {{Doctrine\ORM\Query\ResultSetMapping}} can only be used to query the database for entities using the {{EntityManager::createNativeQuery}} method. It would be great if we could use this as well for objects that are not entities. That way we can create simple DTO's and map them to a query using the {{ResultSetMapping}}.

        I'll open a PR If there are no objections.
        Hide
        Marijn Huizendveld added a comment -

        Thanks for your input. I'll try to work on some tests this week.

        Show
        Marijn Huizendveld added a comment - Thanks for your input. I'll try to work on some tests this week.
        Show
        Marijn Huizendveld added a comment - I've started working on the test suite in this PR .
        Benjamin Eberlei made changes -
        Workflow jira [ 13694 ] jira-feedback [ 14065 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14065 ] jira-feedback2 [ 15929 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15929 ] jira-feedback3 [ 18180 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1819, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Marijn Huizendveld
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: