DDC-3571: Alter ResultSetMapping on NEW DQL (typeMapping for newObjectMappings) #4391

Open
opened 2026-01-22 14:40:52 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 17, 2015).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user ignace:

In the documentation it says that with the NEW operator only scalars are passed but it is limited to only string? Or is it possible to hint it to return floats and integers aswell?

Currently I hacked this together:

private function getIncomeOutgoingPerMonthQuery($year, &$rsm)
    {
        $rsm = new ResultSetMapping();
        $rsm->addScalarResult('sclr0', 'amount_sum', 'integer');

        return $this->createQueryBuilder('t')
            ->select('NEW AppBundle\ValueObject\Money(SUM(t.amount), t.currency), SUBSTRING(t.date, 6, 2) AS HIDDEN month')
            ->where('SUBSTRING(t.date, 1, 4) = :year')
            ->groupBy('t.currency')
            ->addGroupBy('month')
            ->setParameter('year', (int)$year);
    }
Originally created by @doctrinebot on GitHub (Feb 17, 2015). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user ignace: In the documentation it says that with the NEW operator only scalars are passed but it is limited to only string? Or is it possible to hint it to return floats and integers aswell? Currently I hacked this together: ``` private function getIncomeOutgoingPerMonthQuery($year, &$rsm) { $rsm = new ResultSetMapping(); $rsm->addScalarResult('sclr0', 'amount_sum', 'integer'); return $this->createQueryBuilder('t') ->select('NEW AppBundle\ValueObject\Money(SUM(t.amount), t.currency), SUBSTRING(t.date, 6, 2) AS HIDDEN month') ->where('SUBSTRING(t.date, 1, 4) = :year') ->groupBy('t.currency') ->addGroupBy('month') ->setParameter('year', (int)$year); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4391