Paginator adds columns of joined entity to SELECT clause #7549

Open
opened 2026-01-22 15:53:16 +01:00 by admin · 1 comment
Owner

Originally created by @janopae on GitHub (Sep 12, 2025).

Bug Report

Q A
Version 2.20.6

Summary

When joining a relation without adding it to the SELECT, Paginator goes and adds all fields from the relation to the SELECT. This causes breakage to some queries.

Current behavior

Take a look at the following QueryBuilder:

        $queryBuilder
            ->select('product')
            ->join('product.purchase', 'p')
            ->addSelect('max(p.date) AS HIDDEN max_purchase_date')
            ->andWhere('p.user = :userId')
            ->groupBy('product.id')
            ->addOrderBy('max_purchase_date', 'DESC');

I join the relation product.purchase without selecting any fields from it. This is important, because selecting fields (outside of an aggregate function) would break the group by statement (at least on MySQL).

The problem is: As soon as the Paginator steps in (foreach(new Paginator($queryBuilder) {}), all fields from the joined relation get added to the SELECT, leading to the following MySQL error:

#1055 - Expression #12 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'p1_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Is that necessary? If not, we should avoid this.

Expected behavior

I'd prefer the Paginator to understand that these fields should not be part of the result and not add them to the SELECT. But I know the internals of the Paginator too little to know if this is possible, or if the Paginator needs those fields for some of the magic it's doing.

How to reproduce

TODO

Originally created by @janopae on GitHub (Sep 12, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 2.20.6 #### Summary When joining a relation without adding it to the SELECT, Paginator goes and adds all fields from the relation to the SELECT. This causes breakage to some queries. #### Current behavior Take a look at the following QueryBuilder: ```php $queryBuilder ->select('product') ->join('product.purchase', 'p') ->addSelect('max(p.date) AS HIDDEN max_purchase_date') ->andWhere('p.user = :userId') ->groupBy('product.id') ->addOrderBy('max_purchase_date', 'DESC'); ``` I join the relation `product.purchase` **without selecting any fields from it**. This is important, because selecting fields (outside of an aggregate function) would break the group by statement (at least on MySQL). The problem is: As soon as the Paginator steps in (`foreach(new Paginator($queryBuilder) {}`), all fields from the joined relation get added to the SELECT, leading to the following MySQL error: ``` #1055 - Expression #12 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'p1_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ``` Is that necessary? If not, we should avoid this. #### Expected behavior I'd prefer the Paginator to understand that these fields should not be part of the result and not add them to the SELECT. But I know the internals of the Paginator too little to know if this is possible, or if the Paginator needs those fields for some of the magic it's doing. #### How to reproduce TODO <!-- Provide a failing Unit or Functional Test - you can submit one in a Pull Request separately, referencing this bug report. And if you feel like it, why not fix the bug while you're at it? If that is too difficult, provide a link to a minimal repository containing an application that reproduces the bug. If the bug is simple, you may provide a code snippet instead, or even a list of steps. -->
Author
Owner

@janopae commented on GitHub (Sep 12, 2025):

I just found out the problem disappears when I construct the Paginator with new Paginator($queryBuilder, fetchJoinCollection: false).

The docs under https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/tutorials/pagination.html suggest that Doctine developers hope to automate this in the future.

So this issue can probably be closed?

@janopae commented on GitHub (Sep 12, 2025): I just found out the problem disappears when I construct the Paginator with `new Paginator($queryBuilder, fetchJoinCollection: false)`. The docs under https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/tutorials/pagination.html suggest that Doctine developers hope to automate this in the future. So this issue can probably be closed?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7549