DDC-1819: Allow ResultSetMapping to be used for objects that are not entities #2288

Closed
opened 2026-01-22 13:47:26 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (May 11, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user marijn:

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.

Originally created by @doctrinebot on GitHub (May 11, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user marijn: 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.
admin added the Improvement label 2026-01-22 13:47:26 +01:00
admin closed this issue 2026-01-22 13:47:27 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 11, 2012):

Comment created by @beberlei:

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);
@doctrinebot commented on GitHub (May 11, 2012): Comment created by @beberlei: 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); ```
Author
Owner

@doctrinebot commented on GitHub (May 13, 2012):

Comment created by marijn:

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

@doctrinebot commented on GitHub (May 13, 2012): Comment created by marijn: Thanks for your input. I'll try to work on some tests this week.
Author
Owner

@doctrinebot commented on GitHub (May 14, 2012):

Comment created by marijn:

I've started working on the test suite in this PR.

@doctrinebot commented on GitHub (May 14, 2012): Comment created by marijn: I've [started working on the test suite in this PR](https://github.com/doctrine/doctrine2/pull/348).
Author
Owner

@beberlei commented on GitHub (Dec 5, 2020):

This was added with new object mappings in 2.4

@beberlei commented on GitHub (Dec 5, 2020): This was added with new object mappings in 2.4
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2288