GroupBy discriminator #5435

Open
opened 2026-01-22 15:07:44 +01:00 by admin · 5 comments
Owner

Originally created by @raziel057 on GitHub (Feb 28, 2017).

Do you think it could be possible to allow to query grouping by discriminant. For example, we could be able to create a query builder like that, given the fact that we can have different kind of Participants:

/**
* ...
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({
 *     "delegate" = "Delegate",
 *     "journalist" = "Journalist",
 *     ...
 * })
 */
class Participant {
...
$qb = $this->getEntityManager()->createQueryBuilder()
            ->select('DISCRIMINATOR(p) as type, COUNT(p) as count')
            ->from(Participant::class, 'p')
            ->groupBy('DISCRIMINATOR(p)');

Doctrine could simply convert the DISCRIMINATOR(p) to p.discr internally. What do you think about that?

Originally created by @raziel057 on GitHub (Feb 28, 2017). Do you think it could be possible to allow to query grouping by discriminant. For example, we could be able to create a query builder like that, given the fact that we can have different kind of Participants: ```php /** * ... * @ORM\DiscriminatorColumn(name="discr", type="string") * @ORM\DiscriminatorMap({ * "delegate" = "Delegate", * "journalist" = "Journalist", * ... * }) */ class Participant { ... ``` ```php $qb = $this->getEntityManager()->createQueryBuilder() ->select('DISCRIMINATOR(p) as type, COUNT(p) as count') ->from(Participant::class, 'p') ->groupBy('DISCRIMINATOR(p)'); ``` Doctrine could simply convert the ``DISCRIMINATOR(p)`` to ``p.discr`` internally. What do you think about that?
Author
Owner

@ghost commented on GitHub (Jul 9, 2020):

This could be used as ->orderBy('DISCRIMINATOR(p)') too, right? It would be good addition.

@ghost commented on GitHub (Jul 9, 2020): This could be used as `->orderBy('DISCRIMINATOR(p)')` too, right? It would be good addition.
Author
Owner

@beberlei commented on GitHub (Jul 10, 2020):

@guilhermeblanco what do you think?

@beberlei commented on GitHub (Jul 10, 2020): @guilhermeblanco what do you think?
Author
Owner

@AlexeyKosov commented on GitHub (Oct 24, 2021):

Any plans on implementing that? Would be very helpful.

@AlexeyKosov commented on GitHub (Oct 24, 2021): Any plans on implementing that? Would be very helpful.
Author
Owner

@fnagel commented on GitHub (Feb 29, 2024):

Any workaround for this?

@fnagel commented on GitHub (Feb 29, 2024): Any workaround for this?
Author
Owner

@loicpennamen commented on GitHub (May 26, 2025):

Also has this use-case today.

@loicpennamen commented on GitHub (May 26, 2025): Also has this use-case today.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5435